ruby - Controller monkey patch in initializer gets lost when rails reloads classes -


I am trying to add parameter wrapping to I initializers / wrap_parameters.rb I add the following bit:

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

this works when the application starts, but B. I am modifying one of my controller classes, wrapping the parameter immediately stops working as if the controller class was reloaded without the above patch.

How to make my monkey patch consistent?

thanks

I had a similar problem that was trying to first portpatch code That was loading in the lazy rail. I was able to correct my patch by wrapping it in a module, then editing the module in the class that you are editing. There will be something inside a new file in config / initializers:

  Module MyDeviseDecorator wrap_parameters: User, Format: [: json] End class DeviseController & lt; Devise.parent_controller.Constantize MyDeviseDectorator end expansion  

I have a plan class name that may be wrong, which you should match the handpatch you are trying to match. Im not 100% this method will fix your problem just as I have decided but give it a try; I would have left it as a comment, but there was no minimum representative.


Comments