132

我正在运行 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

所以,真的不知道该怎么办。希望我能得到一些快速的帮助。谢谢!

4

5 回答 5

297

我自己在尝试将旧版 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 最终删除了该方法。降级到rubygems2.0.0 之前的任何版本,例如 1.8.25 以暂时恢复功能。您可以使用gem update --system 1.8.25.

顺便说一句,Rails 2.3.5 至少需要更新到 2.3.17。有一些严重的安全漏洞会让您面临一些非常讨厌的攻击。从长远来看,升级到 3.x 需要被视为非常强烈的需求。

于 2013-03-12T00:53:58.027 回答
31

对于 rvm 用户,

rvm install rubygems 1.8.2 --force
于 2014-07-02T11:34:21.227 回答
26

这对我有帮助:http: //djellemah.com/blog/2013/02/27/rails-23-with-ruby-20/

我与 结合使用了此功能gem update --system 1.8.25,您的情况可能不需要。

于 2013-03-25T22:20:14.763 回答
1

另一种方法是安装 slimgems: gem install slimgems. 这是 RubyGems 的一个插入式分支,可以更好地与旧版本配合使用。

于 2019-07-11T10:53:50.257 回答
0

更新:除了@uxp 的回答,如果你在运行 Catalina 的 Mac 上运行这个命令,命令有一个小的变化,你需要添加 -n。

所以命令是sudo gem update --system -n 1.8.25

于 2020-08-10T12:57:25.410 回答