5

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.

vidur punj
  • 5,019
  • 4
  • 46
  • 65
  • 1
    Does this answer your question? [Undefined method \`escape' for URI:Module](https://stackoverflow.com/questions/68174351/undefined-method-escape-for-urimodule) – Ken White Apr 25 '22 at 04:00
  • yes idea is in both mokey patching is the technique used. – vidur punj Apr 25 '22 at 10:54

1 Answers1

8

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.

Eliot Sykes
  • 9,616
  • 6
  • 50
  • 64
vidur punj
  • 5,019
  • 4
  • 46
  • 65
  • 1
    CGI/URI escape are not the same: URI.escape("www.google test.com") => "www.google%20test.com" CGI.escape("www.google test.com") => "www.google+test.com" – fabriciofreitag Jan 24 '23 at 11:04