No such file or directory @ rb_sysopen for external URL / Rails 6.11 / Ruby 3
open-uri
used to (before Ruby 3.0) overwrite Kernel#open
with its own version which also supports reading from external URLs rather than simply opening local files or running commands.
Mixing those two use-cases was quite dangerous and had the potential for serious vulnerabilities if the passed URL was not ensured to be safe everywhere (including third-party code using Kernel#open
).
As such, this behavior to overwrite Kernel#open
was deprecated in Ruby 2.7 and finally removed in Ruby 3.0. To open an external URL, you can use the following code instead:
URI.open("https://brandemia.org/sites/default/files/inline/images/firefox_logo.jpg")
I am not exactly sure where the change comes from, but
require 'open-uri'uri = 'https://brandemia.org/sites/default/files/inline/images/firefox_logo.jpg'URI.open(uri) # ! instead of open without URI
should work.
Updateopen-uri
did declare Kernel#open
until the 3.0 release. Apparently that was deprecated in 2.7. From now on, you need to call URI.open
. See the commit here: https://github.com/ruby/open-uri/commit/53862fa35887a34a8060aebf2241874240c2986a .