14
   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 ?

honey
  • 981
  • 6
  • 19

2 Answers2

9

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.
UptDogTT
  • 91
  • 6
  • Nope, I do not. KT-Paperclip is the "official" fork of Paperclip, if you wanted to go as far as calling it that. It is linked at the top of the readme for the original Paperclip on Github. – UptDogTT Jun 15 '21 at 13:08
  • Just by replacing my paperclip to kt-paperclip in gemfile, my app started working (with ruby 3.1.0-preview1 rails 6.1.4). Thank you. – Nezir Nov 13 '21 at 09:34
  • +1 for `c`. At first I thought it didn't work, then I noticed that I had both `kt-paperclip` and `paperclip` in my Gemfile. Removing `paperclip` did the trick. – Beer Me Jul 28 '22 at 13:10
6

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
Jon Sullivan
  • 193
  • 2
  • 6