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'
精彩评论