Has_one and find_by_id issue

I have two models:

testamonial
photo (has_attachement)

testamonial has_one photo

The issue is when do this:
@testamonial = Testamonial.find_all_by_id(id)

I get “undefined method `photo’ for” in my browser?? BUT here is the
big kicker…

If I do @testamonial = Testamonial.find(:first)

everything works fine and the image is show!.. (find :all works too
when I loop through the objects.)

I tried @testamonial = Testamonial.find_all_by_id(id, :include
=> :photo) That just gave me a bigger query and still no photo…

On 16 May 2008, at 08:56, heimdull wrote:

I get “undefined method `photo’ for” in my browser?? BUT here is the
big kicker…

That returns an array of testamonials, not a single object as
find :first does.

Fred

heimdull wrote:

If I do @testamonial = Testamonial.find(:first)

everything works fine and the image is show!.. (find :all works too
when I loop through the objects.)

Are you sure the id matches the first record in the table?

And thats why I say never post to a forum in the middle of the night :
(

duh…

Changed the view code and its all good now…

Thanks Fred

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