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 %>×
</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)
You need to use
<%=for form_for like:It might be the cause of not showing the rows in the loop.