How to make code in lib / automatically reload when a file changes?

This is a continuation of the question . During development, I have to restart the rails application every time I change the code in lib / for the code changes to take effect. How to get this code for automatic reboot, for example, controllers, models, etc.

+13
ruby-on-rails
May 20 '09 at 3:53
source share
3 answers

For Rails 3 , modify the instructions in the article from @science's answer. In the environments/development.rb file, add the lines:

 ActiveSupport::Dependencies.autoload_paths << File::join( Rails.root, 'lib') ActiveSupport::Dependencies.explicitly_unloadable_constants << 'MyModuleInLibFolder' 

Of course, replace your module name with MyModuleInLibFolder .

+2
Jun 08 '12 at 18:46
source share
 module ActsAsReloadable def self.included(base) ActiveSupport::Dependencies.explicitly_unloadable_constants << base.name if Rails.env == 'development' end end 

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

+1
Dec 21 '11 at 6:53
source share

why not just enter

 load Rails.root + '/lib/your_lib.rb' 
0
Mar 28 '11 at 22:23
source share



All Articles