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

2

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 ?

Gassing answered 17/4, 2021 at 3:49 Comment(0)
C
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.
Cultus answered 13/6, 2021 at 13:43 Comment(3)
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.Cultus
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.Sennar
+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.Goudy
P
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
Periscope answered 28/2, 2022 at 2:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.