How can I force my plugin to reload with each request?

后端 未结 6 521
离开以前
离开以前 2020-12-17 14:43

As I understand it, plugins are not reloaded in Rails with each request in development mode. Which makes sense, as generally you add plugins to your app and it\'s the app yo

6条回答
  •  余生分开走
    2020-12-17 15:04

    This solution, for engines, works on Rails 2.3 but comes with one cavaet, it will load all files in the engine and parent app on every request which will make response times slower.

    # lib/my_engine/engine.rb
    if ENV['RELOAD_MYENGINE'] && Rails.env.development?
      config.to_prepare do
        Rails.logger.debug "RELOADING MY ENGINE"
        require_dependency MyEngine::Engine.root.join('lib', 'my_engine').to_s
      end
    
    config.after_initialize do
      Rails.application.config.reload_classes_only_on_change = false
    end
    

    Then start the server:

    RELOAD_MYENGINE=1 rails server
    

提交回复
热议问题