Ruby-on-rails Rails3 服务器和捆绑器错误:未初始化的常量捆绑器 (NameError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2282969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:18:39  来源:igfitidea点击:

Rails3 server and bundler error: uninitialized constant Bundler (NameError)

ruby-on-railsrubygemsruby-on-rails-3bundler

提问by Pavel Manylov

I just install rails 3 and all gems that it need, but when I try to start server, it says about problem in boot script.

我只安装了 rails 3 和它需要的所有 gem,但是当我尝试启动服务器时,它说引导脚本中存在问题。

[rap-kasta@acerAspire testR3]$ script/rails server  
/home/rap-kasta/tmp/testR3/config/boot.rb:7:in `rescue in <top (required)>': uninitialized constant Bundler (NameError)  
        from /home/rap-kasta/tmp/testR3/config/boot.rb:2:in `<top (required)>'  
        from script/rails:9:in `require'  
        from script/rails:9:in `<main>  

So, I tried to reinstall Bundler, install "pre"-version (but really it has version number lower then i install by gem install bundler

所以,我尝试重新安装 Bundler,安装“pre”-version(但实际上它的版本号低于我安装的版本号 gem install bundler

Now there are next gems in system:

现在系统中有下一个宝石:

abstract (1.0.0)
actionmailer (3.0.0.beta, 2.3.5, 2.3.4)
actionpack (3.0.0.beta, 2.3.5, 2.3.4)
activemodel (3.0.0.beta)
activerecord (3.0.0.beta, 2.3.5, 2.3.4)
activeresource (3.0.0.beta, 2.3.5, 2.3.4)
activesupport (3.0.0.beta, 2.3.5, 2.3.4)
arel (0.2.1, 0.2.pre)
builder (2.1.2)
bundler (0.9.5)
erubis (2.6.5)
fxri (0.3.7)
fxruby (1.6.20)
i18n (0.3.3)
jemini (2010.1.24, 2010.1.5)
mail (2.1.2)
memcache-client (1.7.8)
mime-types (1.16)
mysql (2.8.1)
nifty-generators (0.3.2, 0.3.0)
rack (1.1.0, 1.0.1, 1.0.0)
rack-mount (0.5.1, 0.4.0)
rack-openid (0.2.3, 0.2.2)
rack-test (0.5.3)
rails (3.0.0.beta, 2.3.5, 2.3.4)
railties (3.0.0.beta)
rake (0.8.7)
rawr (1.3.8)
RedCloth (4.2.2)
ruby-mysql (3.0.2)
ruby-openid (2.1.7)
rubygems-update (1.3.5)
rubyzip (0.9.4, 0.9.1)
rubyzip2 (2.0.1)
sqlite3-ruby (1.2.5)
text-format (1.0.0)
text-hyphen (1.0.0)
thor (0.13.2, 0.13.1)
tzinfo (0.3.16)

Also, there is same error with rails consoleand similar with bundle check:

此外,还有与以下相同的错误rails console和类似的错误bundle check

[rap-kasta@acerAspire testR3]$ bundle check
/usr/lib/ruby/gems/1.9.1/gems/bundler-0.9.5/bin/bundle:12:in `rescue in <top (required)>': uninitialized constant Bundler::BundlerError (NameError)
        from /usr/lib/ruby/gems/1.9.1/gems/bundler-0.9.5/bin/bundle:10:in `<top (required)>'
        from /usr/bin/bundle:19:in `load'
        from /usr/bin/bundle:19:in `<main>'

采纳答案by Pavel Manylov

It isn't a bug in Bundler (or Rails), It's a bug (?!) in gems system, I think... So.. I also have gem 'rawr', which have file 'bundler.rb' and gems system load it instead of 'bundler/../bundler.rb'.

这不是 Bundler(或 Rails)中的错误,而是 gems 系统中的错误(?!),我想......所以......我也有 gem 'rawr',它有文件 'bundler.rb' 和 gems系统加载它而不是'bundler/../bundler.rb'。

I removed rawr, but now I can't use jemini... But my problem closed now.

我删除了rawr,但现在我不能使用jemini……但我的问题现在已经解决了。

回答by Marcin Inkielman

it works after adding:

添加后即可使用:

gem install bundler

and after adding:

添加后:

gem 'bundler'

in line 2 in config/boot.rb (just after require 'rubygems')

在 config/boot.rb 的第 2 行中(就在 require 'rubygems' 之后)

回答by kwatch

Please confirm paths of ruby and rake command.

请确认ruby和rake命令的路径。

$ which ruby
/usr/bin/ruby
$ which rake
/usr/local/bin/rake

I got the same error. In my case, I installed Rails with /usr/bin/ruby, but rake uses /usr/local/bin/ruby. This is why I got the error related to Bundler.

我得到了同样的错误。就我而言,我使用 /usr/bin/ruby 安装 Rails,但 rake 使用 /usr/local/bin/ruby。这就是我收到与 Bundler 相关的错误的原因。

回答by jim

I had upgraded my rubygems to 1.5.0 but I needed to also put ruby-1.9.2-p180 as my default ruby version in RVM. This did the trick for me.

我已将 ruby​​gems 升级到 1.5.0,但我还需要将 ruby​​-1.9.2-p180 作为我在 RVM 中的默认 ruby​​ 版本。这对我有用。

回答by Joel Cogen

I had the problem on Mac, because several gems (including bundler) were installed in "/opt/local/lib/ruby/gems/1.8", which is loaded by default by RubyGems in irb, but not in rake.

我在 Mac 上遇到了这个问题,因为在“/opt/local/lib/ruby/gems/1.8”中安装了几个 gems(包括 bundler),它默认由 irb 中的 RubyGems 加载,但不在 rake 中。

Here is how I fixed it, it is probably not perfect, but at least it works:

这是我修复它的方法,它可能并不完美,但至少它有效:

  1. Find the path(s) you need by going in irband doing

    require 'rubygems'
    Gem.path
    => ["/Users/joel/.gem/ruby/1.8", "/opt/local/lib/ruby/gems/1.8"]
    

    These are the default paths, so if everything works for you in irb they're good.

  2. Now, in boot.rb, add (use your paths if they differ of course)

    Gem.path.push "/opt/local/lib/ruby/gems/1.8"
    Gem::Specification.find_by_name('bundler').activate
    

    Right after

    require 'rubygems'
    
  1. 通过进入irb并执行,找到您需要的路径

    require 'rubygems'
    Gem.path
    => ["/Users/joel/.gem/ruby/1.8", "/opt/local/lib/ruby/gems/1.8"]
    

    这些是默认路径,所以如果在 irb 中一切正常,它们就很好。

  2. 现在,在boot.rb 中,添加(当然,如果它们不同,请使用您的路径)

    Gem.path.push "/opt/local/lib/ruby/gems/1.8"
    Gem::Specification.find_by_name('bundler').activate
    

    紧随其后

    require 'rubygems'
    

Hope this solves it for you, at least I'm glad I fixed it for me so I can finally use Rails 3 !

希望这可以为您解决问题,至少我很高兴我为我修复了它,这样我终于可以使用 Rails 3 了!