in Rails this returns an empty string:
response=open(url)
But this works:
response=Net::HTTP.get(URI.parse(url))
I don’t know why include and open work in the commandline, but not in
Rails. Some config setting perhaps? Definitely an exasperating
experience.
Are you sure open works? On a straight commandline, you’ll be using
Kernel.open, which returns an IO object for a file/directory.
It doesn’t know about URIs.
Try loading open-uri, and calling it on the string
require ‘open-uri’
response = url.open
If you want the content, just replace the last line with
page = url.open.readlines
Yeah, I had “require ‘open-uri’” in there. You’re right - without it,
Kernel.open can’t open the URL (I thought I remembered reading in the
docs that Kernel.open could handle URLs though).
in Rails this returns an empty string:
response=open(url)
But this works:
response=Net::HTTP.get(URI.parse(url))
I don’t know why include and open work in the commandline, but not in
Rails. Some config setting perhaps? Definitely an exasperating
experience.
Are you sure open works? On a straight commandline, you’ll be using
Kernel.open, which returns an IO object for a file/directory.
It doesn’t know about URIs.
Try loading open-uri, and calling it on the string
require ‘open-uri’
response = url.open
If you want the content, just replace the last line with