How to call ActiveRecord :: Base load-method?

To perform a special kind of validation in an ActiveRecord-based model, I need to manually perform the update_attributes steps: load (params) && & save

But when I try to call "load" on my Model instance (mymodel.load (params)), it calls "load" on ActiveSupport, trying to load the file.

Can I tell Rails to use the ActiveRecord method?

Thanks!

Relationship Mark

+4
source share
2 answers

I think you need the assign_attribute method of ActiveRecord::Base .

I am using Rails 3.1.3, but hopefully this is right for you.

The update_attributes source you inserted refers to ActiveResource::Base , not ActiveRecord::Base . I made this mistake myself: Is it possible to call ActiveResource :: Base # load? ActiveRecord::Base does not provide a load method. Instead, the load Object method is called, which appears to be provided by the ActiveSupport Loadable module in activesupport-3.1.3/lib/active_support/dependencies.rb .

+2
source

Direct from source:

 # File activerecord/lib/active_record/base.rb, line 2665 def update_attributes(attributes) self.attributes = attributes save end 

These are actually rails 2, but I think it hasn’t changed much.

+1
source

Source: https://habr.com/ru/post/1369381/


All Articles