diff options
author | Robert Speicher <rspeicher@gmail.com> | 2017-02-28 21:34:43 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2017-03-06 22:41:10 +0300 |
commit | 5c41338fa30b5795309957c71202b11a71cccef0 (patch) | |
tree | 5115c177c3abe55fe1e71208fa46a5cec201291f /app/uploaders/gitlab_uploader.rb | |
parent | c4c2ac10d0997dd4e7bc958bca6052144a58839e (diff) |
Handle relative and absolute Upload paths in the Uploaders
Diffstat (limited to 'app/uploaders/gitlab_uploader.rb')
-rw-r--r-- | app/uploaders/gitlab_uploader.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/uploaders/gitlab_uploader.rb b/app/uploaders/gitlab_uploader.rb index bd7de4ed562..d662ba6820c 100644 --- a/app/uploaders/gitlab_uploader.rb +++ b/app/uploaders/gitlab_uploader.rb @@ -1,4 +1,8 @@ class GitlabUploader < CarrierWave::Uploader::Base + def self.absolute_path(upload_record) + File.join(CarrierWave.root, upload_record.path) + end + def self.base_dir 'uploads' end @@ -18,4 +22,15 @@ class GitlabUploader < CarrierWave::Uploader::Base def move_to_store true end + + # Designed to be overridden by child uploaders that have a dynamic path + # segment -- that is, a path that changes based on mutable attributes of its + # associated model + # + # For example, `FileUploader` builds the storage path based on the associated + # project model's `path_with_namespace` value, which can change when the + # project or its containing namespace is moved or renamed. + def relative_path + self.file.path.sub("#{root}/", '') + end end |