mercredi 22 juin 2016

ActiveRecord::Base#assign_attributes monkey patch doesn't work after Rails 4 upgrade

I'm upgrading an existing Rails 3 upgrade to Rails 4. This application monkey patches ActiveRecord::Base#assign_attributes and was working fine in Rails 3; now in Rails 4 the monkey patched code never gets called.

I have a config initializer which requires the monkey patched code from the lib directory and I can see that it is run once during the startup initialization process.

This is a simplified version of the monkey patch file from the lib directory.

# encoding: UTF-8
module ActiveRecord
  class Base
    alias_method :default_assign_attributes, :assign_attributes

    def assign_attributes(new_attributes)
      # Do some custom stuff here
      default_assign_attributes(new_attributes)
    end

  end
end

Aucun commentaire:

Enregistrer un commentaire