Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing reload of library files that are required by an autoloaded library file

Rails 3.2.3. I have a Rails app with /lib in in my autoload paths. One of my library files is requiring a bunch of files like so

Dir[Rails.root.join("lib/foo/*.rb")].each { |f| require f }

In development, those files don't reload if I change them. For example, if I modify /lib/foo/bar.rb, I will have to restart the server to see those changes. Can anyone suggest a way so that on each request they are reloaded properly?

like image 560
axsuul Avatar asked May 18 '12 11:05

axsuul


1 Answers

require doesn't play very nicely with rails' autoloading system.

require_dependency will do pretty much what require does but keeps the autoloading system in the loop so that the loaded constants will get unloaded at the end of the request. You may need to ensure that the files are in rails' autoload paths

like image 69
Frederick Cheung Avatar answered Oct 04 '22 15:10

Frederick Cheung