Cannot require 'nokogiri' in Rails (but works in irb)

后端 未结 2 1790
后悔当初
后悔当初 2021-01-25 20:05

I\'ve just started using Ruby on Rails and so far it\'s working nicely. I\'m now trying to implement a gem but it\'s not working, and I am hoping it\'s just a beginner mistake -

2条回答
  •  佛祖请我去吃肉
    2021-01-25 20:15

    Firstly try changing your controller to be somthing like

    class HomeController < ApplicationController
        require 'nokogiri'
        require 'open-uri'
    
        def index
            url = "http://www.walmart.com/search/search-ng.do?search_constraint=0&ic=48_0&search_query=batman&Find.x=0&Find.y=0&Find=Find"
            doc = Nokogiri::HTML(open(url))
            @mattVar = doc.at_css("title").text
        end
    end
    

    I'm guessing you are also using bundler, check that you have include this gem and run bundle install.

    You can find the documentation for this at http://gembundler.com/

提交回复
热议问题