How can I keep my initializer configuration from being lost in development mode?

后端 未结 2 1070
别那么骄傲
别那么骄傲 2021-02-18 22:24

I\'m working on a Rails app that uses an engine. I\'m using an initializer to configure one of my engine\'s controllers so that it will trigger an action in the host app. The co

2条回答
  •  醉酒成梦
    2021-02-18 22:38

    You can add as many to_prepare blocks as you want - when you do config.to_prepare, Rails is doing (in configuration.rb in railties)

    def to_prepare(&blk)
      to_prepare_blocks << blk if blk
    end
    

    and then iterates over those blocks handing them over to ActionDispatch::Reloader, where to_prepare is implemented using ActiveSupport::Callbacks (i.e. the same thing that is used for before_save and so on). Multiple to_prepare blocks are fine.

    Currently it looks like Rails iterates over to_prepare_blocks after reading application initialisers so adding to Rails.application.configuration.to_prepare should work. You may prefer to use ActionDispatch::Reloader.to_prepare.

提交回复
热议问题