How to call ActiveRecord::Base's load-method?
To do a special kind of validation in an ActiveRecord-based model I need to manually do the update_attributes-steps: load(params) && save
But when I try to call "load" on my Model's instance (m开发者_如何学运维ymodel.load(params)) it calls "load" on ActiveSupport, trying to load a file.
Is there a way to tell Rails to use the ActiveRecord-method?
Thanks!
Regards Marc
I think you want the assign_attribute
method of ActiveRecord::Base
.
I'm using Rails 3.1.3, but hopefully this is correct for you.
The update_attributes
source you pasted belongs to ActiveResource::Base
, not toActiveRecord::Base
. I just made that mistake myself: Is it possible to call ActiveResource::Base#load? ActiveRecord::Base
does not supply a load
method. Instead the load
method of Object
is called, which appears to be supplied by ActiveSupport's Loadable
module in activesupport-3.1.3/lib/active_support/dependencies.rb
.
Straight from the source:
# File activerecord/lib/active_record/base.rb, line 2665
def update_attributes(attributes)
self.attributes = attributes
save
end
Actually it's rails 2, but I imagine it didn't change all that much.
精彩评论