Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails nokogiri no such file or directory

Gemfile

...
gem 'nokogiri'
...

In controller

doc = Nokogiri::HTML(open('http://google.com'))

And I got a error

Errno::ENOENT in SiteController#scrap
No such file or directory - http://google.com
app/controllers/site_controller.rb:6:in `initialize'
app/controllers/site_controller.rb:6:in `open'
app/controllers/site_controller.rb:6:in `scrap'

I tried delete Gemfile.lock and do "bundle install" again, but it's not resolved my problems.

rails 2.3.8

ruby 1.9.3p194

What am I doing wrong? Thanks in advance for your help

like image 429
Tom Avatar asked Nov 15 '12 08:11

Tom


1 Answers

You need to require 'open-uri' if you want to pass URLs to open(). Additionally, you'll need to read the file after opening it:

require 'open-uri'
doc = Nokogiri::HTML(open('http://google.com').read)
like image 162
Chris Heald Avatar answered Oct 07 '22 19:10

Chris Heald