Gem加载irb但不加载控制台

lam*_*tor 6 ruby bundle rubygems ruby-on-rails-3

这个让我疯了.我可以通过irb加载一个gem:

steve@server:/var/www/listings$ irb
irb(main):001:0> Gem.path
=> ["/home/steve/.gem/ruby/1.9.1", "/usr/local/ruby/lib/ruby/gems/1.9.1"]
irb(main):002:0> require 'nokogiri'
=> true
Run Code Online (Sandbox Code Playgroud)

但我无法通过rails控制台加载它:

irb(main):001:0> Gem.path
=> ["/home/steve/.gem/ruby/1.9.1", "/usr/local/ruby/lib/ruby/gems/1.9.1"]
irb(main):002:0> require 'nokogiri'
=> false
Run Code Online (Sandbox Code Playgroud)

宝石(nokogiri)已安装

steve@server:/var/www/listings$ gem which nokogiri
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri.rb
Run Code Online (Sandbox Code Playgroud)

捆绑同意

steve@server:/var/www/listings$ bundle show nokogiri
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1
Run Code Online (Sandbox Code Playgroud)

但是,当然,rake spec失败了

/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:304:in `rescue in depend_on': No such file to load -- Nokogiri (LoadError)
Run Code Online (Sandbox Code Playgroud)

其他环境信息:

steve@server:/var/www/listings$ ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
steve@server:/var/www/listings$ rails --version
Rails 3.0.1
steve@server:/var/www/listings$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
  - INSTALLATION DIRECTORY: /usr/local/ruby/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /usr/local/ruby/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/ruby/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/local/ruby/lib/ruby/gems/1.9.1
     - /home/steve/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/
Run Code Online (Sandbox Code Playgroud)

有什么建议??

编辑

顺便说一下,Nokogiri在Gemfile中,捆绑安装完成而没有投诉.

这是一个我从Windows迁移到Ubuntu的项目.在Windows上它工作正常(奇怪的是!)所以我很确定这是一个环境问题.

jas*_*man 14

如果已加载该文件,则require返回false.通过连续两次执行require语句,在irb会话中尝试一下.第二个将返回false:

irb(main):001:0> require 'nokogiri'
=> true
irb(main):002:0> require 'nokogiri'
=> false
Run Code Online (Sandbox Code Playgroud)

如果找不到该文件,则require会引发LoadError.

你的异常消息(没有这样的文件加载 - Nokogiri),使得它似乎需要'Nokogiri'而不是'nokogiri',这可能是一个区分大小写的操作系统的问题.

  • 我的猜测也是一个案例问题,在不区分大小写的Windows环境中"消失".我建议OP尝试`grep -FR Nokogiri .`(从应用程序的根目录)尝试找到大写提及. (3认同)