This repository was archived by the owner on Jul 13, 2023. It is now read-only.
This repository was archived by the owner on Jul 13, 2023. It is now read-only.
Wrong URL for attachments using relative_url_root #889
Closed
Description
If I set a relative root URL for my Rails app using config.action_controller.relative_url_root = '/sub'
, links to attachments don't include /sub
, i.e. :
- got: https://example.com/system/documents/assets/...
- expected: https://example.com/sub/system/documents/assets/...
Here's a quick fix but it breaks a bunch of tests. I didn't go through the code thoroughly, this should probably be fixed in a better way.
diff --git lib/paperclip/attachment.rb lib/paperclip/attachment.rb
index 5a92761..ceabe68 100644
--- lib/paperclip/attachment.rb
+++ lib/paperclip/attachment.rb
@@ -23,7 +23,7 @@ module Paperclip
- :url => "/system/:class/:attachment/:id_partition/:style/:filename",
+ :url => ":rails_relative_url_root/system/:class/:attachment/:id_partition/:style/:filename",
diff --git lib/paperclip/interpolations.rb lib/paperclip/interpolations.rb
index 1f867b3..81600a0 100644
--- lib/paperclip/interpolations.rb
+++ lib/paperclip/interpolations.rb
@@ -75,6 +75,11 @@ module Paperclip
+ # Returns the relative_url_root constant as a string.
+ def rails_relative_url_root attachment, style_name
+ Rails.application.config.action_controller.relative_url_root.to_s
+ end
+
(to_s
to make sure we get an empty string if the constant is not defined)
Related: #25
Metadata
Metadata
Assignees
Labels
No labels
Activity