Ruby-on-rails Gem:Module 的未定义方法 `source_index' (NoMethodError)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15349869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
undefined method `source_index' for Gem:Module (NoMethodError)
提问by noodleboy347
I'm running a Rails 2.3.5 application and upon running script/server I am shown the following:
我正在运行 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
If I comment out line 60 in boot.rb (Rails::GemDependency.add_frozen_gem_path) and run script/server, I get this:
如果我在 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
So, not really sure what to do. Hoping I can get some quick help. Thanks!
所以,不确定该怎么做。希望我能得到一些快速的帮助。谢谢!
回答by uxp
I just ran into this problem myself while trying to upgrade an older Rails app from REE 1.8.7 to 1.9.3-p385. Oddly, Ruby 1.9.3-p327 works just fine. What it came down to was ruby-1.9.3-p385 had installed RubyGems version 2.0.2 for me, and 1.9.3-p327 has RubyGems v1.8.23 installed.
我在尝试将旧的 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_indexhas been deprecated for a while, but since Rails 2.3 is not getting any updates except critical security patches, this will never get fixed. RubyGems v2.0 finally removed that method. Downgrade to any rubygemsversion prior to 2.0.0, like 1.8.25 to get the functionality back for now. You can get a compatible version using gem update --system 1.8.25.
Gem.source_index已经弃用了一段时间,但由于 Rails 2.3 除了关键的安全补丁之外没有得到任何更新,这永远不会得到修复。RubyGems v2.0 最终删除了该方法。降级到rubygems2.0.0 之前的任何版本,例如 1.8.25 以暂时恢复功能。您可以使用gem update --system 1.8.25.
As a very important aside, Rails 2.3.5 needs to be updated to a minimum of 2.3.17. There are critical security vulnerabilities that open you up to some very nasty attacks. In the long term, upgrading to 3.x needs to be considered a very strong need.
非常重要的一点是,Rails 2.3.5 需要更新到至少 2.3.17。有一些严重的安全漏洞会让您面临一些非常讨厌的攻击。从长远来看,升级到 3.x 需要被认为是非常强烈的需求。
回答by Arivarasan L
for rvm users,
对于 rvm 用户,
rvm install rubygems 1.8.2 --force
回答by ippa
This helped me: http://djellemah.com/blog/2013/02/27/rails-23-with-ruby-20/
这对我有帮助:http: //djellemah.com/blog/2013/02/27/rails-23-with-ruby-20/
I did this in combination with gem update --system 1.8.25, which might not be needed for your case.
我是与 结合使用的gem update --system 1.8.25,您的情况可能不需要。
回答by johnnyb
Another way to do this is to install slimgems: gem install slimgems. This is a drop-in fork of RubyGems that works better with old versions.
另一种方法是安装 slimgems:gem install slimgems. 这是 RubyGems 的一个直接分支,在旧版本上运行得更好。

