views:

214

answers:

2

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

A: 

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.

theIV
+2  A: 

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! =)

Staelen