Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload all gems in Rails 3?

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?

like image 859
Trevor Burnham Avatar asked Aug 05 '10 20:08

Trevor Burnham


1 Answers

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!

like image 86
m4risU Avatar answered Oct 21 '22 08:10

m4risU