def moods
if mymoods.empty?
else
mymoods.collect{|mm| mm.mood}
end
end
In Rails2, User.first.moods returns an array of moods (or an empty
array where there are none)
In Rails3, I get a big old error: uninitialized constant Mymood::Mood
I'm guessing it's something to do with lazy loading, because if I call
(in the console)
User.first.mymoods
then
User.first.moods
it all works as it should, but if I just call on its own:
User.first.moods
I get the error above
def moods
ms=Mymood.where('user_id=?',user_id)
if ms.empty?
else
ms.collect{|mm| mm.mood}
end
end
But it seems strange to have to write another query in the middle of a
model. I'd have thought that the "has_many :mymoods" in the user model
would have been enough.