views:

986

answers:

5

I am attempting to get a gem I've just installed working in a rails application. I can require the gem just fine in a ruby program that I run from the command line using:

require 'nokogiri'

But when I attempt to do the same in one of my rails controllers it errors saying "no such file to load -- nokogiri".

I tried using the full path to the lib/nokogiri.rb file, but that fails because it cannot find "nokogiri/native"

Thanks

A: 

Try the following

require 'rubygems'  
gem 'nokogiri'

If you are on some form of *nix then did you get any errors when you installed the gem, particularly errors stating that the gem was not on the path. This may happen if you have installed the gem as yourself rather than as root and you do not have your personal gem library in your gem path.

If you always install your gems using

sudo gem install some_gem_name

then you should not get that problem.

Steve Weet
This gives:Could not find RubyGem nokogiri (>= 0)Could it be named differently?
Eric
See later edit. Are you running on windows or some form of *nix
Steve Weet
i'm running on windows
Eric
Hmm. In that case I would try Brian's solution.
Steve Weet
+2  A: 

Better, place the following in your environment.rb file:

Rails::Initializer.run do |config|
  ...
  config.gem :nokogiri
  ...
end

This will tell Rails that you depend on that particular gem. It also allows you to specify particular versions, and it will automatically keep all your gems synched, or unpack them into vendor/gems if you so wish.

Brian Guthrie
+1 this is a better long-term solution however I think he may have a mis-installed gem.
Steve Weet
A: 

Ok I figured it out. This is going to sound pretty stupid...but oh well...

It turns out I had two installations of ruby on my machine. I use InstantRails to serve my test applications and it comes prepackaged with an installation of ruby. I had another installation however outside of this and it was here that nokogiri had been installed, not in the installation in InstantRails.

In any case they were looking in different spots for the gems.

Thanks a bunch for your help!!

Eric
+1  A: 

I had a similar error but simply forgot to put the following in my environment.rb file: (note the quoted "nokogiri")

Rails::Initializer.run do |config|
  ...
  config.gem "nokogiri"
  ...
end
pagetribe