Controller monkey patch in initializer gets lost when rails reloads classes

前端 未结 1 330
孤城傲影
孤城傲影 2021-01-06 02:17

I am trying to monkey patch controller classes in a third party gem. To be precise, I am trying to add parameter wrapping to devise controllers. In initializers/wrap_p

相关标签:
1条回答
  • 2021-01-06 03:16

    I had a similar issue before with trying to monkeypatch code that is lazy loaded in rails. I was able to fix it by wrapping my patch in a module then extending the module in the class you are editing. It would be something like this inside a new file in config/initializers:

    module MyDeviseDecorator
      wrap_parameters :user, format: [:json]
    end
    
    class DeviseController < Devise.parent_controller.constantize
        extend MyDeviseDectorator
    end
    

    I may have a devise class name wrong, it should match whatever you are trying to monkeypatch. Im not 100% this method will fix your problem like it fixed mine but give it a try; I would have left this as a comment but didnt have the minimum rep.

    0 讨论(0)
提交回复
热议问题