Reputation: 53
I wrote a Ruby script in which I use Nokogiri.
For Rails I made this module in the lib/
directory:
require "net/http"
require "uri"
require 'nokogiri'
Module gk_CT
class CT
def getCT
uri = URI.parse("http://www.website.com")
CT = Net::HTTP.get_response(uri)
proc = Nokogiri::HTML(CT.body)
CTQ = Array.new
CTQ << proc.css('td')
end
end
In the controller I have:
require 'gk_CT'
def show
@CT= gk_CT::CT.getCT()
respond_to do |format|
format.html # show.html.erb
format.json { render json: @CT}
end
end
It always gives me the error:
cannot load such file -- nokogiri
and I have no idea why.
Upvotes: 4
Views: 9133
Reputation: 9700
If the script is part of an actual Rails project, then you need to add Nokogiri to the Gemfile (with the line gem 'nokogiri'
). If you're not in a Rails project or aren't using Bundler or some such weird thing, you'll still need to install the gem (gem install nokogiri
).
Upvotes: 5