Ruby on Rails Thursday, February 9, 2017

hmm, ok.  I'll add the has many products to my cart.rb file.   Here is my current cart index.  
Are you suggesting I nest my product loop in my cart?


<% @carts.each do |cart| %>
<td><%= cart.created_at.strftime("%m/%d/%Y") %> | <%= cart.product_id %> </td>
<td><%#= link_to 'Show', cart %></td>
<td><%#= link_to 'Edit', edit_cart_path(cart) %></td>

<% if not cart.processing? %>
<td>| <%= link_to 'Remove', cart, method: :delete, data: { confirm: 'Are you sure?' } %> </td>
<% else %>
<td> <%= '| Processing order...' %> </td>
<% end %>
<% end %>

On Thursday, February 9, 2017 at 4:04:25 PM UTC-5, Colin Law wrote:
On 9 February 2017 at 17:49, Joe Guerra <> wrote:
> I've got a simple cart table with a link to a product id.
> I'd like to grab the values from the product table that match the product id
> in the cart, but I'm looping thru the cart in an index view.
> So, I wasn't quite sure how to accomplish this.

Assuming that you have Cart has_many products, and if you haven't then
you probably should have, then you can say (if the cart is in @cart)

@cart.products.each do |product|
  # at this point product contains the Product


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment