如何重新加载Rails 3中的所有宝石? [英] How to reload all gems in Rails 3?

查看:87
本文介绍了如何重新加载Rails 3中的所有宝石?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一些方法可以重新加载Rails应用程序中的所有gem,而无需重新启动服务器?我有一个使用:path 的Gemfile来引用我在同一个系统上开发的依赖项,并且很烦人的是必须杀死该应用程序并执行 rails -s 每次保存一次更改。生产中也能很好地更新宝石,而不会在几秒钟内终止服务器。想法?

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?

推荐答案

最近我发现我想和你说的一样,所以我可以和我一起开发宝石项目。

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

在一个Gemfile中,我没有包含gem dependency,而是添加到了 config / environments / development.rb

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"

这需要我做一些额外的工作,但在大多数情况下,它是可以的。当我完成一个gem的工作时,我可以删除自动加载并在Gemfile中使用gem依赖。

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.

请记住,gem依赖可以放在:production,:test 组,因此在开发中您已清除它。

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

快乐编码!

这篇关于如何重新加载Rails 3中的所有宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆