NoMethodError

Hello,
When i test this code

contenu de votre panier

<% for item in @items product = item.product %> <% end %>
<%= item.quantity %> <%= h(product.title)%> <%=item.unit_price %> <%=item.unit_price * item.quantity %>

I saw this message

NoMethodError in Store#display_cart

Showing app/views/store/display_cart.rhtml where line #5 raised:

undefined method `product’ for 5.0:Float

Extracted source (around line #5):

2:


3: <%
4: for item in @items
5: product = item.product
6: %>
7:
8:

RAILS_ROOT:
/Users/bolomichelin/Documents/Creation_Perso/Developement
/depot/public/…/config/…

But when i test this code, it’s working
<%= @items.size %>

Can u help me ?

Thanks

<%= item.quantity %>

8:

<%= item.quantity %>
<%= h(product.title)%>

should be

<%= h(item.title)%>

The error message told you exactly where the problem is.

NoMethodError in Store#display_cart
Showing app/views/store/display_cart.rhtml where line #5 raised:
undefined method `product’ for 5.0:Float
Extracted source (around line #5):

Of course I always blaze right by that too :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs