How do I make the code in lib/ automatically reload when the file changes?

后端 未结 4 1259
误落风尘
误落风尘 2020-12-30 05:39

This is a follow up to this question. During development I have to restart the rails app everytime I change the code in lib/ in order for the code changes to take effect. Ho

4条回答
  •  攒了一身酷
    2020-12-30 05:57

    module ActsAsReloadable
      def self.included(base)
        ActiveSupport::Dependencies.explicitly_unloadable_constants << base.name if Rails.env == 'development'
      end
    end
    

    To use it, simply include ActsAsReloadable in your lib/* files and add config.autoload_paths += %W(#{config.root}/lib) in config/application.rb

提交回复
热议问题