Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:46:02+00:00 2026-06-17T15:46:02+00:00

In this code: < % @products.each do |product| %> <div class=entry> <%= image_tag(product.image_url) %>

  • 0

In this code:

<

    % @products.each do |product| %>
      <div class="entry">
        <%= image_tag(product.image_url) %>
        <h3><%= product.title %></h3>
        <p><%= sanitize(product.description) %></p>
        <div class="price_line">
          <span class="price"><%= number_to_currency(product.price) %></span>
    <!-- START_HIGHLIGHT -->
          <%= button_to 'Add to Cart', line_items_path(product_id: product),
            remote: true %>
    <!-- END_HIGHLIGHT -->
        </div>
      </div>
    <% end %>

At the bottom where we have button_to method with the params passed to it:

    <%= button_to 'Add to Cart', line_items_path(product_id: product),
        remote: true %>

Looking at the code, here is my understanding of what is going on, Did I understand it correctly or I have missed something?

In that code we are creating a button with text of “Add to Cart” and then we are
passing the product_id of the prodcut varaible to it, which is coming
from that for-each loop at the top and telling it go to link_items page with a
POST method for a product with ID of product_id .

Another question: in the lines_items_path could we just pass product.product_id ? or that wouldn’t work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:46:03+00:00Added an answer on June 17, 2026 at 3:46 pm

    I think it is an example from the Agile Web Development with Rails book. I read it long time ago… if I remember it right, there are products, orders and line_items.

    if you call rake routes you will se that line_items_path, as POST, is the route for thecreate action in the line_items_controller. More details: CRUD verbs and actions

    So, you are passing the product_id to the create action, where you should have something like:

    def create
      product = Product.find(params[:product_id])
    ...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a picture gallery, that uses this code to display each product
I am using a div for each product list called result-products and within it
In this piece of code: ActionController::Routing::Routes.draw do |map| map.resources :line_items map.resources :orders map.resources :products
I have downloaded the sample code from this site for FTP Client http://www.lysesoft.com/products/andftp/index.html But
I've an issue with this piece of code: NSURL *url = [[NSURL alloc] initWithString:@http://authenticate.radonsystems.net/products.xml];
This code produces a different output in Python 2 and Python 3 . class
I have a PHP loop like this <?php foreach ($products as $product) { ?>
I'm looping through each relevant tag in an XML file and executing this code.
I have two pictures on top of each other: Here is the code: <div
I have 25 products showing in a page. Each product contains a form within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.