我正在运行Rails 2.3.5应用程序,在运行脚本/服务器时,我会看到以下内容:
./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)
from ./script/../config/boot.rb:60:in `load_initializer'
from ./script/../config/boot.rb:44:in `run'
from ./script/../config/boot.rb:17:in `boot!'
from ./script/../config/boot.rb:123
from script/server:2:in `require'
from script/server:2
如果我在boot.rb(Rails :: GemDependency.add_frozen_gem_path)中注释掉第60行并运行脚本/服务器,我就明白了:
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:298:in `add_gem_load_paths'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:132:in `process'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from /home/developer/bigpink/config/environment.rb:13
from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/developer/bigpink/vendor/rails/railties/lib/commands/server.rb:84
from script/server:3:in `require'
from script/server:3
所以,不确定该怎么做。希望我能得到一些快速的帮助。谢谢!
答案 0 :(得分:293)
我在尝试将旧的Rails应用程序从REE 1.8.7升级到1.9.3-p385时遇到了这个问题。奇怪的是,Ruby 1.9.3-p327工作正常。它归结为ruby-1.9.3-p385为我安装了RubyGems版本2.0.2,1.9.3-p327安装了RubyGems v1.8.23。
Gem.source_index
已被弃用了一段时间,但由于Rails 2.3除了关键安全补丁之外没有获得任何更新,因此永远不会得到修复。 RubyGems v2.0最终删除了该方法。降级到2.0.0之前的任何rubygems
版本,如1.8.25,以便暂时恢复功能。您可以使用gem update --system 1.8.25
获得兼容版本。
另外,Rails 2.3.5需要更新至最低2.3.17。有一些严重的安全漏洞可以让你受到一些非常讨厌的攻击。从长远来看,升级到3.x需要被视为非常强烈的需求。
答案 1 :(得分:28)
对于rvm用户,
rvm install rubygems 1.8.2 --force
答案 2 :(得分:24)
这帮助了我:http://djellemah.com/blog/2013/02/27/rails-23-with-ruby-20/
我与gem update --system 1.8.25
结合使用,您的情况可能不需要。
答案 3 :(得分:0)
另一种方法是安装苗条:gem install slimgems
。这是RubyGems的一个直接插入的分支,可与旧版本一起使用。
答案 4 :(得分:0)
更新:除了@uxp答案以外,如果您在运行Catalina的Mac上运行此命令,则命令会有小的变化,您需要添加-n。
所以命令应该是sudo gem update --system -n 1.8.25