为什么我的rake调用会导致“undefined method `source_index`”错误?

3

我想运行bundle exec rake db:migrate,但遇到以下错误。

bundle exec rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
undefined method `source_index' for Gem:Module
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/initializer.rb:298:in `add_gem_load_paths'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/initializer.rb:132:in `process'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/initializer.rb:113:in `run'
C:/Program Files/chiliproject-3.7.0/config/environment.rb:42:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `block in require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:547:in `new_constants_in'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/tasks/misc.rake:4:in `block in <top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
C:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
C:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
C:/Ruby193/bin/rake:23:in `load'
C:/Ruby193/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate => environment

这部分代码遇到了错误:

    def self.add_frozen_gem_path
      @@paths_loaded ||= begin
        source_index = Rails::VendorGemSourceIndex.new(Gem.source_index)
        Gem.clear_paths
        Gem.source_index = source_index
        # loaded before us - we can't change them, so mark them
        Gem.loaded_specs.each do |name, spec|
          @@framework_gems[name] = spec
        end
        true
      end
    end

我知道这似乎很基础,但我在互联网上搜索了很久,似乎找不到答案。


我正在使用1.9.2和Rake 0.8.7,出现了相同的错误。将Rake更改为0.9.6后,仍然出现相同的错误。 - Evolve
5个回答

5

1

好的,我整天都在搞这个,最终通过以下步骤使事情顺利进行:

  1. 将 RVM 更新到最新版本

    rvm get head

  2. 将 Ruby 版本更改为 1.9.3

    • 在 Gemfile 中更新
    • 在 .rvmrc 文件中更新
  3. 将 Rails 更新到最新的 2.3 版本

    • 在 Gemfile 中更新
    • 在 environments.rb 中更新

完成以上步骤后运行

bundle exec rake db:migrate

Rails 2.3 中存在与最新的 ruby gems 和一个未知的 X 因素发生冲突的奇怪问题,其中可能包括 ruby 1.9.1 和 1.9.2 的问题。


0

来自ApiDock

该类已被弃用或移至最新稳定版本。此处显示的是最后一个现有版本(v2.3.8)。

在问题中,使用的是Rails版本2.3.17,由于已被弃用,因此会出现错误。如果使用的是2.3.8,则可以正常工作。


我在我的gemfile中将rails版本更改为2.3.8并运行了bundle install和其他一些操作。再次运行db:migrate后,我遇到了一个新的错误: rake aborted! undefined method `autoload_paths' for #Rails::Configuration:0x3b84658。 这是遇到错误的部分: config.autoload_paths +=%W(#{RAILS_ROOT}/app/sweepers) . . 。

Liquid drops

config.autoload_paths +=%W(#{RAILS_ROOT}/app/drops)我将它们注释掉,错误又回到了“undefined method `source_index' for Gem:Module”。
- yuji
是的,我也遇到了同样的问题,现在正在苦思冥想如何解决。 - Evolve

0

这个错误信息:undefined method `source_index' for Gem:Module (NoMethodError) 的意思是:

Gem.source_index 方法已经被弃用了一段时间,但由于 Rails 2.3 已经不再更新除了关键安全补丁之外的内容,所以这个问题将永远不会得到解决。RubyGems v2.0 最终删除了该方法。现在可以降级到任何 rubygems 版本,比如 1.8.25,来暂时恢复功能。

所以我猜现在的问题与 Rails 2.3 冲突有关,而当前的 RubyGems 版本也可能存在问题。

我尝试了以下操作:

  1. gem install rubygems-update -v '1.8.25'
  2. gem uninstall rubygems-update # 然后删除其他版本。

但没有什么效果,只是分享我的发现。


rubygems_update gem 有点像元安装器。它安装升级程序的安装器。是的,删除所有其他版本的 gem,然后您需要运行 rubygems_update 以实际提交该版本作为您的 gem --version - uxp

0

将你的 gem 更新到 1.8.25 版本

gem update --system 1.8.25

这个可能会对你有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接