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

我知道这似乎是基本的,但我一直在互联网上搜索,似乎无法找到答案。

4

5 回答 5

5

完美解决了 Gem:Module (NoMethodError) 的未定义方法 `source_index'的问题,只有简单的行

gem update --system 1.8.25
于 2013-08-23T22:18:27.520 回答
1

好的,我整天都在搞砸这个问题,最后通过以下方式让事情对我有用:

  1. 更新 RVM

    rvm 得到头

  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 中的问题?

于 2013-03-14T00:16:06.447 回答
1

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

Gem.source_index 已经被弃用了一段时间,但由于 Rails 2.3 除了关键的安全补丁之外没有任何更新,这永远不会得到修复。RubyGems v2.0 最终删除了该方法。降级到 2.0.0 之前的任何 ruby​​gems 版本,例如 1.8.25 以暂时恢复功能。

所以我现在的猜测是它与 Rails 2.3 与当前的 RubyGems 冲突有关。我这样做了:

  1. gem install ruby​​gems-update -v '1.8.25'
  2. gem uninstall ruby​​gems-update # 并删除了其他版本。

没有什么不同,只是分享我的发现。

于 2013-03-13T06:52:52.160 回答
0

将您的宝石更新到 1.8.25

gem update --system 1.8.25

可能会对您有所帮助。

于 2014-03-11T08:04:10.110 回答
0

ApiDock

此类已弃用或在最新的稳定版本上移动。此处显示了最新的现有版本 (v2.3.8)。

在这个问题中,使用了 Rails 版本 2.3.17,并且由于被弃用,它给出了一个错误。如果是 2.3.8,它可以工作。

于 2013-03-12T23:49:16.790 回答