Gem:Module的未定义方法`source_index'(NoMethodError)


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

因此,不是很确定该怎么做。希望我能得到一些快速的帮助。谢谢!

Answers:


294

我只是在尝试将较旧的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被认为是非常需要的。


非常感谢!效果很好。是的,谢谢,我正在升级到2.3.17,然后升级到最新的3.x。
noodleboy347

@uxp有关此问题的任何提示:stackoverflow.com/questions/15374188/…–
演变

87
使用RVM的任何人都可以致电rvm rubygems latest-1.8降级rubygems并解决此问题。
马丁

1
Martin的评论(使用RVM的任何人都可以将rvm ruby​​gems最新版1.8降级到rubygems并解决此问题。)帮助我解决了这个问题,因为几个小时以来我一直陷入困境。非常感谢。
Prajkta P 2014年

30
需要强迫降级红宝石:rvm rubygems --force latest-1.8
马特·怀特

28

对于rvm用户,

rvm install rubygems 1.8.2 --force

1
我必须回到1.6.2才能完成这项工作。但是,此命令是必需的。
赞恩


0

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

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.