The following code uses partial template. My question is: What happened to the looping of cart items? add_to_cart.rhtml <div class="cart-title">Your Cart</div> <table> <% for cart_item in @cart.items %> <tr> <td><%= cart_item.quantity %>ラ</td> <td><%= h(cart_item.title) %></td> <td class="item-price"><%= number_to_currency(cart_item.price) %></td> </tr> <% 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", :action => :empty_cart %> Refactored add_to_cart.rhtml <div class="cart-title">Your Cart</div> <table> <%= render(:partial => "cart_item", :collection => @cart.items) %> <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", :action => :empty_cart %> _cart_item.rhtml <tr> <td><%= cart_item.quantity %>ラ</td> <td><%= h(cart_item.title) %></td> <td class="item-price"><%= number_to_currency(cart_item.price) %></td> </tr>></tr> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Oct 14, 2006, at 9:31 AM, Bala Paranj wrote:> The following code uses partial template. My question is: What > happened to the looping of cartThe :collection parameter causes render(0 to invoke the template once for each item in the collection. Dave --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi, the method <%= render(:partial => "cart_item", :collection => @cart.items) %> iterates a partial render for the :collection content: for each item the @cart.items collection the partial in "_cart_item.rhtml" is rendered, in this partial code the variable name to refer for one item is intended to be called "cart_item", like the partial name.> _cart_item.rhtml > > <tr> > <td><%= cart_item.quantity %>צlt;/td> > <td><%= h(cart_item.title) %></td> > <td class="item-price"><%= number_to_currency(cart_item.price) %></td> > </tr> > > > </tr>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---