简体   繁体   中英

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

  require 'rubygems' 
  require 'nokogiri'

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

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 because 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.

Hope that helps.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM