我添加了一些额外的东西来自动获取路径.如果 Rails.env.development?reload_gems = %w(my_gem other_gem) # 应该自动重新加载的宝石名称config.autoload_paths += Gem.loaded_specs.values.inject([]){ |a,gem|a += gem.load_paths 如果 reload_gems.include?宝石名称;一种 }需要active_support/dependencies"ActiveSupport::Dependencies.explicitly_unloadable_constants += reload_gems.map { |gem|gem.classify }结尾本地 gem 可以用 gem 'my_gem', :path => 添加'../my_gem'I've got a Rails app which uses a gem I'm actively developing. How can I instruct the app to reload the gem on every request? 解决方案 This solution almost works but for some reason I have to put it into application.rb and not in environments/development.rb otherwise the autoload_paths are not recognized.I added some additional stuff which fetches the paths automagically.if Rails.env.development? reload_gems = %w(my_gem other_gem) # names of gems which should autoreload config.autoload_paths += Gem.loaded_specs.values.inject([]){ |a,gem| a += gem.load_paths if reload_gems.include? gem.name; a } require 'active_support/dependencies' ActiveSupport::Dependencies.explicitly_unloadable_constants += reload_gems.map { |gem| gem.classify }endLocal gems can be added with gem 'my_gem', :path => '../my_gem' 这篇关于如何在开发模式下为每个请求重新加载 gem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-07 12:22