开发者

Gem loads in irb but not console

This one is driving me nuts. I can load a gem via irb:

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

But I can't load it through the rails console:

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

The gem (nokogiri) is installed

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

And bundle agrees

steve@server:/var/www/listings$ bundle show nokogiri
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1

But, of course, rake spec fails with

/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)

Other environment info:

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/

Any suggestions??

Edit

By the way, Nokogiri is in the Gemfile and bundle install completes without complaint.

This is a project I'm moving from windows to Ubuntu. On windows it's working fine (oddly enough开发者_如何学C!) so I'm pretty sure it's an environment thing.


require returns false if that file has already been loaded. Try it out in your irb session by performing the require statement twice in a row. The second one will return false:

irb(main):001:0> require 'nokogiri'
=> true
irb(main):002:0> require 'nokogiri'
=> false

If the file could not be found, require will raise a LoadError instead.

Your exception message (No such file to load -- Nokogiri), makes it seem like something is requiring 'Nokogiri' instead of 'nokogiri', which might be a problem on a case-sensitive operating system.


Make sure that you require it in your Gemfile and do a bundle install.

Edit - Try requiring rubygems, then nokogiri.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜