I have the following code to get google.com
class Geocoder
def self.locate()
uri="http://www.google.com/"
puts Net::HTTP.get(uri)
end
but i faced with the erorr:
undefined method `hostname' for "'http://www.google.com/":String (NoMethodError)
I have already seen this, and my ruby version is: ruby 2.2.1
You're missing parsing the string into a URI... Here is what it should look like:
class Geocoder
def self.locate(address)
escaped_address = URI.escape(address)
uri = URI.parse(escaped_address)
puts Net::HTTP.get(uri)
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With