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. How do I get this code to automatically reload like controllers, models, etc?
For Rails 3, vary the instructions given in the article from @science's answer. In your environments/development.rb
file, add the lines:
ActiveSupport::Dependencies.autoload_paths << File::join( Rails.root, 'lib')
ActiveSupport::Dependencies.explicitly_unloadable_constants << 'MyModuleInLibFolder'
Of course, substitute the name of your module for MyModuleInLibFolder
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With