Skip to content

Commit

Permalink
Experiment with options to supress Paperclip warnings
Browse files Browse the repository at this point in the history
We're getting hundreds of "warning: URI.escape is obsolete" messages.
  • Loading branch information
javierm committed Aug 15, 2021
1 parent 16dd5f6 commit 0c15391
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/ckeditor/picture.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Ckeditor::Picture < Ckeditor::Asset
has_attached_file :data,
url: "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
url_generator: ConsulUrlGenerator,
path: ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
styles: { content: "800>", thumb: "118x100#" }

Expand Down
1 change: 1 addition & 0 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Document < ApplicationRecord
include DocumentsHelper
include DocumentablesHelper
has_attached_file :attachment, url: "/system/:class/:prefix/:style/:hash.:extension",
url_generator: ConsulUrlGenerator,
hash_data: ":class/:style/:custom_hash_data",
use_timestamp: false,
hash_secret: Rails.application.secrets.secret_key_base
Expand Down
1 change: 1 addition & 0 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Image < ApplicationRecord
thumb: "140x245#"
},
url: "/system/:class/:prefix/:style/:hash.:extension",
url_generator: ConsulUrlGenerator,
hash_data: ":class/:style",
use_timestamp: false,
hash_secret: Rails.application.secrets.secret_key_base
Expand Down
2 changes: 1 addition & 1 deletion app/models/site_customization/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SiteCustomization::Image < ApplicationRecord
"logo_email" => [400, 80]
}.freeze

has_attached_file :image
has_attached_file :image, url_generator: ConsulUrlGenerator

validates :name, presence: true, uniqueness: true, inclusion: { in: VALID_IMAGES.keys }
validates_attachment_content_type :image, content_type: ["image/png", "image/jpeg"]
Expand Down
12 changes: 12 additions & 0 deletions lib/consul_url_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ConsulUrlGenerator < Paperclop::UrlGenerator

private

def escape_url(url)
if url.respond_to?(:escape)
super
else
URI::DEFAULT_PARSER.escape(url).gsub(escape_regex){|m| "%#{m.ord.to_s(16).upcase}" }
end
end
end

0 comments on commit 0c15391

Please sign in to comment.