NoMethodError (undefined method `rating_before_type_cast' - Relief
October 12th, 2007
All I can say is this was a nasty, irritating, soul-destroying bug to find.
As I understand it (and I haven't really tried to), there are certain conditions when using virtual attributes (using the term quite lightly, basically an attribute which is transient, or not reflected into the db table) on a model when a method missing implementation will try to read the value of the attribute. So, the solution is to insert a different method_missing implementation earlier in the invocation chain.
Please note, this is not my own work. I found the the solution at this blog. And, apparently, that blog found it in the Rails Recipe book.
For the sake of posterity, in case the 'Made of Stone' blog disappears, I'm going to post the fix here also.
def method_missing(symbol, *params)
if (symbol.to_s =~ /^(.*)_before_type_cast$/)
send $1
else
super
end
end
Leave a Reply