Missing attribute in activerecord

I have models Foo and Bar . Bar has a foo_id column. When I call Bar.foo_id , I get the missing attribute: foo_id error message missing attribute: foo_id

Keep in mind that this is not an undefined method error, and the column is definitely in db. What are some common reasons for this?

thanks

+6
ruby ruby-on-rails activerecord
source share
2 answers

This probably has something to do with your find method? For example, you did a: select in the search:

 Foo.find(:all, :select => "firstvar, secondvar") 

In this case, you can only access firstvar and secondvar, even if you specified foo_id

Hope this helps! =)

+35
source share

You call

 Bar.foo_id 

or

 bar = Bar.new bar.foo_id 

If you don't have a class variable for Bar , you need to look at foo_id for an instance of Bar. Hope this helps. Greetings.

+2
source share

All Articles