Argh sorry...
Again:
Hey,
I''d like to add some "magic" functionality to some model by
chain
aliasing an attributes setter method like this:
class Thing < ActiveRecord::Base
def name_with_upcase=(r)
self.name_without_upcase=(r.upcase)
end
alias_method_chain "name=", :upcase
end
This (on script/console) gives me this error:
NameError: /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/
active_support/core_ext/module/aliasing.rb:33:in `alias_method'':
undefined method `name='' for class `Thing''
Seems like model doesn''t know about its attributes at this point.
Even if I add my aliasing code after the class:
class Thing < ActiveRecord::Base
end
Thing.class_eval <<-eos
def name_with_upcase=(r)
self.name_without_upcase=(r.upcase)
end
alias_method_chain "name=", :upcase
eos
I get the same error.
But if I add a simple
puts Thing.new
between the class and the eval part, it works.
Any ideas how I can force the model to load it''s attributes earlier?