7

Is there some way to reload all gems in a Rails app without completely restarting the server? I've got a Gemfile that uses :path to reference a dependency that I'm developing on the same system, and it's annoying to have to kill the app and do rails -s again every time I save a change. It'd also be nice in production to be able to update a gem without killing the server for a few seconds. Thoughts?

Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196

1 Answers1

6

Recently I found that I would like to do the same as you say, so I can develop gems along with my projects.

In a Gemfile I did not include gem dependency, but instead I added in config/environments/development.rb

ActiveSupport::Dependencies.autoload_paths << "/path_to_gem_dir/gem_name/lib"

It requires me to do some additional work with making it sync, but in most common cases it is ok. When I finish working on a gem I can remove autoload and use gem dependency in Gemfile.

Remember that gem dependency can be placed in :production, :test groups, so in development you have it cleaned.

For example

group :development do
  # gem "wirble" COMMENTED!, so I can autoload files!
end

group :production do
  gem "wirble"
end

Happy coding!

m4risU
  • 1,231
  • 11
  • 14
  • Thanks for the tip! I would add that if the gem you are working on has extra dependencies (in the gemspec), you should add them to the development group of your gemfile or else they won't be loaded. – Pierre Olivier Martel Mar 10 '11 at 20:03
  • Yea, you can only add sources there. I still did not managed to find fully automated way for doing this, but for now it seems the closest one :) – m4risU Mar 10 '11 at 20:55