首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的rake调用导致了一个'undefined method `source_index`‘错误?

为什么我的rake调用导致了一个'undefined method `source_index`‘错误?
EN

Stack Overflow用户
提问于 2013-03-13 07:21:59
回答 5查看 12.5K关注 0票数 3

我正在尝试运行bundle exec rake db:migrate,然后遇到了以下错误。

代码语言:javascript
复制
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

这是遇到错误的部分:

代码语言:javascript
复制
    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

我知道这看起来很基本,但我一直在网上搜索,似乎找不到答案。

EN

回答 5

Stack Overflow用户

发布于 2013-08-24 06:18:28

这个问题在undefined method `source_index' for Gem:Module (NoMethodError)中得到了完美的解决,只需要简单的一行

代码语言:javascript
复制
gem update --system 1.8.25
票数 5
EN

Stack Overflow用户

发布于 2013-03-13 14:52:52

这个:undefined method `source_index' for Gem:Module (NoMethodError)

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

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

  1. gem安装rubygems-更新-v '1.8.25'
  2. gem卸载rubygems-更新#并刚刚删除了其他版本。

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

票数 1
EN

Stack Overflow用户

发布于 2013-03-14 08:16:06

好的,我已经花了一整天的时间来处理这件事,最终通过以下几点让事情为我所用:

  1. 使远程虚拟机保持最新状态

rvm get head

  • 将ruby版本更改为1.9.3

代码语言:javascript
复制
- Update in Gemfile
- Update .rvmrc file

  1. 将Rails更新到最新的2.3版

代码语言:javascript
复制
- Update in Gemfile
- Update in environments.rb

做完所有这些之后运行

软件包exec rake db:迁移

在Rails 2.3中与最新的ruby gem和未知的x因素发生了一些奇怪的冲突,这可能包括ruby 1.9.1和1.9.2中的问题?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15374188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档