The controller monkey patch in the initializer is lost when the rails reload classes

I am trying to use monkey controller plugin classes in a third-party gem. To be precise, I'm trying to add a wrapping parameter for controller development. In initializers/wrap_parameters.rbI added the following bit:

Rails.application.config.after_initialize do
  DeviseController.class_eval do
    wrap_parameters :user, format: [:json]
  end
end

It works great when the application starts, but when I change one of my controller classes, the parameter wrapper stops working immediately. As if the controller class was rebooted without the above patch.

How to make my monkey patch permanent?

thank

+4
source share
1 answer

, monkeypatch, . , , , . - config/initializers:

module MyDeviseDecorator
  wrap_parameters :user, format: [:json]
end

class DeviseController < Devise.parent_controller.constantize
    extend MyDeviseDectorator
end

, , monkeypatch. Im 100% , , ; , .

+1

All Articles