'Getting a LoadError when using nokogiri gem in my ruby on rails application

When I put in a require statement to load the nokogiri gem I get a load error: no such file to load -- nokogiri

requires:

  require 'rubygems' 
  require 'nokogiri'

gemfile:

source 'https://rubygems.org'
source 'http://gems.github.com'

gem 'rails', '3.2.3'
gem 'rubygems'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'

gem 'json'

# HTML Parser
gem 'nokogiri'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

Also I am using ruby v1.8



Solution 1:[1]

I was having the same problem as you, but at last, I didn't need those "require" to make it work.

The problem I was having was that I didn't restarted the Application after installing nokogiri. Once I restarted the app, nokogiri worked just fine without those 2 "require" lines. The only "require" I needed at last was the "open-uri" because I was trying to scrap a remote page.

Solution 2:[2]

I guess you did put the require 'nokogiri' inside the config/boot.rb. That's not the place, to do that.

Put it just at beginning of the file where you want to use it, or in an initializer or so.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 grilix