简体   繁体   English

Rails - 使用thin时的bundler错误

[英]Rails - bundler error when using thin

I started using bundler and have some problems getting it working. 我开始使用bundler并且在使用它时遇到一些问题。 I have the following gemfile: 我有以下gemfile:

source "http://rubygems.org"
gem "rack", "~>1.1"
gem 'pg','>= 0.8.0'
gem 'rails','2.3.8'
gem 'authlogic','2.1.3'
gem 'ajaxful_rating','2.2.3'
gem 'will_paginate','2.3.12'
gem 'right_aws','1.10.0'
gem 'aws-s3','0.6.2'
gem 'declarative_authorization','0.4.1'
gem 'timeline_fu','0.3.0'
gem 'friendly_id','>= 3.1'

Notice that I specificy that I want to use rack 1.1 (1.1.0). 请注意,我具体说我想使用rack 1.1(1.1.0)。

I get the following error when I run with thin (Webrick works fine): 我运行瘦时遇到以下错误(Webrick工作正常):

thin start
>> Using rails adapter
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:27:in `setup': You have already activated rack 1.2.1, but your Gemfile requires rack 1.1.0. Consider using bundle exec. (Gem::LoadError)
 from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
 from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
 from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:17:in `setup'
 from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler.rb:100:in `setup'
 from /home/vmplanet/Documents/maga/config/../config/preinitializer.rb:16
 from /home/vmplanet/Documents/maga/config/boot.rb:28:in `load'
 from /home/vmplanet/Documents/maga/config/boot.rb:28:in `preinitialize'
 from /home/vmplanet/Documents/maga/config/boot.rb:10:in `boot!'
 from /home/vmplanet/Documents/maga/config/boot.rb:126
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
 from /home/vmplanet/Documents/maga/config/environment.rb:7
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/rack/adapter/rails.rb:42:in `load_application'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/rack/adapter/rails.rb:23:in `initialize'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/rack/adapter/loader.rb:48:in `new'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/rack/adapter/loader.rb:48:in `for'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/thin/controllers/controller.rb:163:in `load_adapter'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/thin/controllers/controller.rb:67:in `start'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/thin/runner.rb:177:in `send'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/thin/runner.rb:177:in `run_command'
 from /home/vmplanet/.gem/ruby/1.8/gems/thin-1.2.7/lib/thin/runner.rb:143:in `run!'

So basically it is complaining that I am using rack 1.2.1 (which is not the case, I can't think of anything using it). 所以基本上它抱怨我使用机架1.2.1(事实并非如此,我想不出任何使用它的东西)。

Any thoughts? 有什么想法吗?

Thin itself depends on Rack. 薄本身取决于 Rack。 And because Thin will load itself before it loads your application, the most recent version of Rack will already be loaded when bundler first enters the picture. 并且因为Thin会在加载应用程序之前加载自身,所以当捆绑器首次进入图片时,最新版本的Rack将被加载。

You have to force the correct version of Rack to Thin. 您必须强制正确版本的Rack to Thin。 In theory you could only have Rack 1.1.0 in your system gems, but that's hardly maintainable or portable. 从理论上讲,你的系统宝石只能使用Rack 1.1.0,但这很难维护或移植。 The error message already contains the answer; 错误消息已包含答案; use bundle exec . 使用bundle exec

bundle exec thin start

So basically it is complaining that I am using rack 1.2.1 (which is not the case, I can't think of anything using it). 所以基本上它抱怨我使用机架1.2.1(事实并非如此,我想不出任何使用它的东西)。

I thought the same thing but it is the case. 我想的是同样的事情,但情况确实如此。 Rubygems is using the latest version. Rubygems正在使用最新版本。 Bundler allows you to override this default by using Bundler允许您通过使用覆盖此默认值

bundle exec foo

When you install a gem to the system, Rubygems creates wrappers for every executable that the gem makes available. 当您向系统安装gem时,Rubygems会为gem提供的每个可执行文件创建包装器。 When you run an executable from the command line without bundle exec, this wrapper invokes Rubygems, which then uses the normal Rubygems activation mechanism to invoke the gem's executable. 当你从没有bundle exec的命令行运行一个可执行文件时,这个包装器调用Rubygems,然后使用普通的Rubygems激活机制来调用gem的可执行文件。 This has changed in the past several months, but Rubygems will invoke the latest version of the gem installed in your system, even if your Gemfile.lock specifies a different version. 这在过去几个月已经发生了变化,但Rubygems将调用系统中安装的最新版本的gem,即使你的Gemfile.lock指定了不同的版本。 In addition, it will activate the latest (compatible) installed version of dependencies of that gem, even if a different version is specified in your Gemfile.lock. 此外,它将激活该gem的最新(兼容)安装版本的依赖项,即使您的Gemfile.lock中指定了不同的版本。 source 资源

You can find information on heroku's site about using thin. 您可以在heroku的网站上找到关于使用瘦身的信息。 Also they are recommend using thin. 他们也建议使用薄。 http://devcenter.heroku.com/articles/rails3#webserver http://devcenter.heroku.com/articles/rails3#webserver

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM