warning: URI.escape is obsolete when using paperclip in ruby 2.7.2

3.3k views Asked by At
   ruby - 2.7.2
   rails - 6.0
   paperclip - 6.1.0

I am getting following warning in my console, while using paperclip gem with ruby 2.7.2

   /Users/***/.rvm/gems/ruby-2.7.2/gems/paperclip-6.1.0/lib/paperclip/url_generator.rb:68: warning: URI.escape is obsolete

I know there are no maintainers for paperclip and it is deprecated but I cannot use active storage as I found paperclip is the easiest and best way for implementing attachments. How can I solve this warning ?

2

There are 2 answers

3
UptDogTT On

When you say "solve" the warning it's not quite clear what you might consider to be an acceptable solution. But you could:

  • a) Ignore the warning so long as you are sticking with these versions of Ruby and Rails, as it does not mean that anything is broken.
  • b) Write some code to suppress this specific warning, though I'd probably not do this as you'd increase the chance of forgetting about the issue, and then ending up with a more acute and time-sensitive problem down the road, if you upgraded part of your system to where URI.escape was no longer available.
  • c) Do what I've done in my Rails application, which is switch to a forked and maintained version of Paperclip, KT-Paperclip. If you wanted to update to the minimum version number that addresses these deprecation warnings, you'd choose 6.4.
0
Jon Sullivan On

Wellll the right answer is to do something better for your codebase as @UptDogTT suggests... but if you just need a get-it-done answer, this monkey patch adds URI.escape back using equivalent functionality. Add it as an initializer:

module URI
  def self.escape url
    URI::Parser.new.escape url
  end
end