简体   繁体   中英

cannot load such file - Nokogiri rails

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.

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

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