I have models Foo
and Bar
. Bar
has column foo_id
.
When I call Bar.foo_id
I get the error missing attribute: foo_id
Keep in mind that this is not an undefined method error and the column definitely is in the db. What are some common causes of this?
Thanks
Probably it has something to do with your find method? For instance you did a :select in a find:
Foo.find(:all, :select => "firstvar, secondvar")
In that case, you can only access firstvar and secondvar even though you have foo_id defined
Hope it helps! =)
Are you calling
Bar.foo_id
or
bar = Bar.new
bar.foo_id
Unless you have a class variable for Bar
, you need to look at foo_id
on an instance of Bar. I hope that helps. Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With