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 7499117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:42:28+00:00 2026-05-29T19:42:28+00:00

The following code in my cart is skipping the loop for each item and

  • 0

The following code in my cart is skipping the loop for each item and only outputting the total, correctly giving the overall cart total.

Does anyone know why this is? There is not any error given.
I am using Rails 3.1.0, and Ruby 1.9.2.

<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>

<div class="cart_title">Your Cart</div>
<table>
  <% for item in @cart.line_items %>
    <% form_for item do |f| %>
      <tr>
        <td>
          <%= f.submit value: 'Update Qty' %>
          <%= f.text_field :quantity, size: 1 %>&times;
        </td>
        <td class="item_price"><%= number_to_currency(item.total_price) %></td>
      </tr>
    <% end %>
  <% end %>
  <tr class="total_line">
    <td colspan="2">Total</td>
    <td class="total_cell"><%= number_to_currency(@cart.total_price) %></td>
  </tr>
</table>

<%= button_to 'Empty cart', @cart, method: :delete,
    confirm: 'Are you sure?' %>

Development.log shows this activity for a cart with two products in it (quantity 1 of each):

Started GET "/carts/7" for 127.0.0.1 at 2012-02-15 16:23:43 +0000
  Processing by CartsController#show as HTML
  Parameters: {"id"=>"7"}
  Cart Load (0.1ms)  SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT 1  [["id", "7"]]
  LineItem Load (0.1ms)  [1mSELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = 7
  Product Load (0.1ms)  SELECT "products".* FROM "products" WHERE "products"."id" = 10 LIMIT 1
  Product Load (0.1ms)  [1mSELECT "products".* FROM "products" WHERE "products"."id" = 11 LIMIT 1
Rendered carts/show.html.erb within layouts/application (41.4ms)
Completed 200 OK in 48ms (Views: 46.5ms | ActiveRecord: 0.9ms)
  • 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-05-29T19:42:30+00:00Added an answer on May 29, 2026 at 7:42 pm

    You need to use <%= for form_for like:

    <%= form_for item do |f| %>
    

    It might be the cause of not showing the rows in the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a header.html which start with session_start();. Then the following code, $_SESSION['cart'][$sw_id] is
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
I have used the following code to display product details in my shopping cart
In my code, I have the following objects to implement a shopping cart: public
This following code snippet works in FF, IE and Chrome. However It does not
In my view I currently have the following code: <%= Html.Hidden(Cart.CartID, Model.Cart.CartID) %> When
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
Following code iterates through many data-rows, calcs some score per row and then sorts
following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666
The following code works great in IE, but not in FF or Safari. I

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.