I suggest you to study a little about ruby before starting with rails. This
also is a "problem" about variable scope.
To use a variable in the view, it must be an instance variable, in your
case:
@photos = Photo.order(:title)
and in the view you have 2 errors: `|products|` should be `|photo|` and
inside the loop you must use the `photo` variable (which have a different
value every cycle of the loop).
<% @photos.each do |photo| %>
<%= photo.user_id %>
<% end %>
2014-04-10 9:19 GMT+02:00 Alfredo Barrero <[email protected]>:
> Ok yeah get it.
>
> Another issue that I have had is the following:
>
> In the users/show.html.erb I'm using the following lines:
>
> <% @photos.each do |product| %>
>
> <%= @photo.user_id %>
>
> <% end %>
>
> In the user controller I have declare this : photos = Photo.order(:title),
> but the browser gives me this error:
>
> undefined method `each' for nil:NilClass in the following line -> <%
> @photos.each do |product| %>
>
> Could you please tell me what I'm doing wrong?.
>
> Thank you and best regards.
>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/09c80a52-bc93-49e2-a23b-98b24b01d0d2%40googlegroups.com<https://groups.google.com/d/msgid/rubyonrails-talk/09c80a52-bc93-49e2-a23b-98b24b01d0d2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/CAK4fz2pug0243LqQFNUYTi8e-zOE%3DLVEiphTw%2BVknuXG7ZA14w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.