Error of "undefined method `each' for #<Picture:0x927dea0>"

hi all,

I have an error “undefined method `each’ for #Picture:0x927dea0
what is that mean?

in my view


<% @user.each do |p| %>
<%= p.image %>
<% end %>

in controller

           @user=picture.all(
     :joins => :culture,
                  :conditions => (Album.joins(:description))).first

plz give me some advance

Simple. You get only one picture object (the first one) because you’re
using
.first method. Since you have only one object, you can’t iterate over it
using the each loop. Get it?

Just use @user.image instead in the view :slight_smile:

On Fri, Jun 10, 2011 at 12:23 PM, Dheeraj K.
[email protected]wrote:

Simple. You get only one picture object (the first one) because you’re
using .first method. Since you have only one object, you can’t iterate over
it using the each loop. Get it?

Just use @user.image instead in the view :slight_smile:

or remove the .first if you want to display all user images.

maybe it’s just me but i suggest you rename your variables. given the
error
you had

undefined method `each’ for #Picture:0x927dea0

it would be easier if you change @user to @pictures.

            :joins => :culture,

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

you exectued people.all.first
so the @user only has one picture object
instead of an array of pictures

2011/6/10 joanne [email protected]

Thanks all. :D…
and i have other question… when i take the image file (BLOD)… i cannot
display it … do you have any idea…
Please give me some advice… thanks …\

On Fri, Jun 10, 2011 at 12:19 AM, 3dd13 [email protected] wrote:

I have an error “undefined method `each’ for #Picture:0x927dea0

plz give me some advance


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

On 10 June 2011 15:47, joanne ta [email protected] wrote:

and i have other question…

If you have another question, please start another thread.

when i take the image file (BLOD)… i cannot
display it … do you have any idea…
Please give me some advice… thanks …\

How do you ‘take it’? What code are you using to display it, and what
errors do you get?

i am have any error about the code… but i cannot show/ display picture
on
the screen

On Fri, Jun 10, 2011 at 10:50 AM, Michael P. [email protected]
wrote:

errors do you get?

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