paperclipruby-on-rails-7ruby-3

undefined method `escape' for URI:Module in ruby 3


After updating my Rails application from Rails 6.0.1 to Rails 7.0.2.3

I am getting issue with the gem "paperclip", '~> 6.1.0'

while using it in application is gives error:

ActionView::Template::Error (undefined method `escape' for URI:Module
Did you mean?  escape_once):

Usage in my application:

<%= image_tag current_user.image.url('med'), width: "36px" %>

How to resolve this issue when bug is present in the ruby gemfile itself, thanks in advance.


Solution

  • The solution to this situation do a monkey patching to the missing method in library.

    add a ruby filke uri_escape.rb inside the initializers folder:

    add lines for monkey patching:

    module URI
      def self.escape(url)
        encode_www_form_component(url)
      end
    end
    

    and its done.