开发者

Rails not recognizing Ruby's Net module

开发者 https://www.devze.com 2023-03-16 11:37 出处:网络
I am trying to access the contents of the webpage of a target URL using the code: def fetch_url(url) r = Net::HTTP.get_response( URI.parse( url ) )

I am trying to access the contents of the webpage of a target URL using the code:

def fetch_url(url)
    r = Net::HTTP.get_response( URI.parse( url ) )
    (r.is_a?(Net::HTTPSuccess)) ? r.body : nil
end

However, for some reason Rails is not able to identify开发者_运维百科 Net, which is a Ruby module from v. 1.9.2 -- why would this be (I used require 'Net' at the top of my code)?

LoadError in PagesController#home

no such file to load -- Net


It's not require 'Net'. You need this:

require 'net/http'
0

精彩评论

暂无评论...
验证码 换一张
取 消