I’m using the following snippet in a Rails app:
require 'open-uri'
url = "http://..."
uri = URI.parse(self.url)
file = open(uri)
puts "path: #{file.path}"
Which works on some files from the web, then crashes on others with:
undefined method `path’ for #< StringIO:0x00000102a47240 >
Any way to fix this strange, intermittent problem?
Don’t use Open::URI like that.
Simply do:
Then you can
readthe file because you have an IO-type object:or
If you need the path, parse the URL with URI and get the path that way.