Fix for remote filesytem paperclip configuration.

This commit is contained in:
Senén Rodero Rodríguez
2017-09-24 01:33:31 +02:00
parent 1a8fda9352
commit e58feb7d6d
3 changed files with 5 additions and 5 deletions

View File

@@ -13,7 +13,7 @@ class DirectUploadsController < ApplicationController
if @direct_upload.valid? if @direct_upload.valid?
@direct_upload.save_attachment @direct_upload.save_attachment
@direct_upload.relation.set_cached_attachment_from_attachment(URI(request.url)) @direct_upload.relation.set_cached_attachment_from_attachment
render json: { cached_attachment: @direct_upload.relation.cached_attachment, render json: { cached_attachment: @direct_upload.relation.cached_attachment,
filename: @direct_upload.relation.attachment.original_filename, filename: @direct_upload.relation.attachment.original_filename,

View File

@@ -24,11 +24,11 @@ class Document < ActiveRecord::Base
before_save :set_attachment_from_cached_attachment, if: -> { cached_attachment.present? } before_save :set_attachment_from_cached_attachment, if: -> { cached_attachment.present? }
after_save :remove_cached_attachment, if: -> { cached_attachment.present? } after_save :remove_cached_attachment, if: -> { cached_attachment.present? }
def set_cached_attachment_from_attachment(prefix) def set_cached_attachment_from_attachment
self.cached_attachment = if Paperclip::Attachment.default_options[:storage] == :filesystem self.cached_attachment = if Paperclip::Attachment.default_options[:storage] == :filesystem
attachment.path attachment.path
else else
prefix + attachment.url attachment.url
end end
end end

View File

@@ -32,11 +32,11 @@ class Image < ActiveRecord::Base
before_save :set_attachment_from_cached_attachment, if: -> { cached_attachment.present? } before_save :set_attachment_from_cached_attachment, if: -> { cached_attachment.present? }
after_save :remove_cached_attachment, if: -> { cached_attachment.present? } after_save :remove_cached_attachment, if: -> { cached_attachment.present? }
def set_cached_attachment_from_attachment(prefix) def set_cached_attachment_from_attachment
self.cached_attachment = if Paperclip::Attachment.default_options[:storage] == :filesystem self.cached_attachment = if Paperclip::Attachment.default_options[:storage] == :filesystem
attachment.path attachment.path
else else
prefix + attachment.url attachment.url
end end
end end