ActiveRecord::MissingAttributeError in MyController#my_action ..... missing attribute: my_attribute
So I got this error message today after I added a column to my database. WTF?? The column exists.. why can’t ActiveRecord see it? oh.. maybe because I am stupid. In my find command I was using the :select option
@widgets = Widget.find(:all, :select=>"id,name")
ActiveRecord can’t see any other attributes aside from what you specify in the :select option, so I just needed to add my attribute to the :select option
@widgets = Widget.find(:all, :select=>"id,name,my_attribute")




#1 by Mike Blyth on September 26, 2010 - 12:29 pm
Quote
Haven’t run into that error yet but it’s great to be aware of … you could probably spend a long time trying to figure it out if you didn’t know!
#2 by stz on January 13, 2011 - 1:05 pm
Quote
Thank you for this post. I was exactly that stupid in this moment and this is the first helpful google result