Gem:Module の未定義メソッド `source_index' (NoMethodError) 質問する

Gem:Module の未定義メソッド `source_index' (NoMethodError) 質問する

Rails 2.3.5 アプリケーションを実行していますが、script/server を実行すると次のように表示されます。

./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 の 60 行目 (Rails::GemDependency.add_frozen_gem_path) をコメントアウトして script/server を実行すると、次のようになります。

=> 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

それで、何をしたらいいのかよくわかりません。すぐに助けてもらえればと思っています。ありがとう!

ベストアンサー1

私自身、古い 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はしばらくrubygems前から非推奨でしたが、Rails 2.3 は重要なセキュリティ パッチ以外の更新が行われないため、この問題は修正されません。RubyGems v2.0 では最終的にこのメソッドが削除されました。今のところ機能を回復するには、1.8.25 など、2.0.0 より前のバージョンにダウングレードしてください。 を使用して互換性のあるバージョンを取得できますgem update --system 1.8.25

非常に重要な補足として、Rails 2.3.5 は最低でも 2.3.17 にアップデートする必要があります。重大なセキュリティ上の脆弱性があり、非常に厄介な攻撃を受ける可能性があります。長期的には、3.x へのアップグレードは、非常に重要な必要性として考慮する必要があります。

おすすめ記事