Skip to content
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
@infertux

Description

@infertux

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. :

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions