我已经安装了Rails 3.0.10和3.1,因为我试图将两者用于两个不同的项目。
在我的Rails 3.0.10项目中,我的Gemfile顶部有以下内容:

gem 'rails', '3.0.10'

但是,在运行bundle install; bundle exec rails --version之后,我得到以下结果:
/Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:31:in `setup': You have already activated activesupport 3.1.1, but your Gemfile requires activesupport 3.0.10. Using bundle exec may solve this. (Gem::LoadError)
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:17:in `setup'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler.rb:110:in `setup'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/cli.rb:340:in `exec'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/vendor/thor/task.rb:22:in `send'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/vendor/thor.rb:263:in `dispatch'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/vendor/thor/base.rb:386:in `start'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/bundler-1.0.21/bin/bundle:13
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/bin/bundle:19:in `load'
    from /Users/bradley/.rbenv/versions/ree-1.8.7-2011.03/bin/bundle:19

有什么想法吗显然,我已经在使用bundle execbundle show rails; bundle show activesupport确认我应该使用正确版本的gems我只需要卸载Rails 3.1吗?

最佳答案

我也遇到过同样的问题。
即使我明确指定要在Gemfile中使用的activesupport版本:

gem 'rails', '3.2.9'
gem 'activesupport', '3.2.9'

当我运行bundle exec rails s时仍然会出现此错误:
/home/tyler/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.0.18/lib/bundler/runtime.rb:31:in `block in setup':
You have already activated activesupport 3.2.10, but your Gemfile requires activesupport 3.2.9. Consider using bundle exec. (Gem::LoadError)

当我想在我的应用程序中返回到一个旧版本的Rails来测试两个版本的Rails之间的差异时,就会发生这种情况。
因此,即使为我的应用程序创建一个单独的gemset(我们通常都会这样做)也不能解决这个问题,因为gemset被这个应用程序本身“污染”(在回到Rails 3.2.9之前临时安装/使用rails3.2.10),而不是被其他应用程序污染!
到目前为止,我找到的唯一解决方案是卸载您不希望它使用的新版本:
gem uninstall activesupport -v 3.2.10

看起来这要么是Bundler中的一个bug,要么是Rails中的一个bug(如果它在加载Bundler之前做了一些导致activesupport被加载/激活的事情,那么我们不能真的把它归咎于Bundler…)。
另一个同样糟糕的解决方案是:要暂时禁用gem的较新版本而不卸载它,可以编辑gem的规范文件(例如/home/tyler/.rvm/gems/ruby-1.9.3-p194/specifications/activesupport-3.2.10.gemspec),并在顶部添加一行raise 'disabled'bundler将跳过加载activesupport 3.2.10(在解救并打印错误之后),并继续加载它可以找到的下一个最高版本的activesupportactivesupport 3.2.9)。
当您准备好重新启用activesupport 3.2.10时,只需删除raise
这可能比卸载和重新安装gem要快,如果您只是想在返回到gem的新版本之前使用旧版本测试一些东西。

07-24 09:49
查看更多