error code
undefined method `each' for nil:NilClass
my products controller code
def index
#@products = Product.all
@products = Product.where(gender: 'male').take
end
html.erb code
<% @products.each do |product| %>
<h3><%= link_to product.title, product %></h3>
<p>On sale by <%= product.user.name %></p>
<% end %>
I get an error when I try to use the second query, but the first one works (Product.all) works fine. I have looked at many other problems like this and cannot solve it. Can anyone help?
Aucun commentaire:
Enregistrer un commentaire