Use absolute urls on document cached_attachment

This commit is contained in:
Senén Rodero Rodríguez
2017-08-30 15:50:32 +02:00
parent 57930df535
commit 5e6d1d799f
2 changed files with 5 additions and 5 deletions

View File

@@ -115,8 +115,8 @@ module CommentableActions
def recover_documents_from_cache(resource)
return false unless resource.try(:documents)
resource.documents = resource.documents.each do |document|
if document.cached_attachment.present? && File.exists?(document.cached_attachment)
document.attachment = File.open(document.cached_attachment)
if document.cached_attachment.present?
document.attachment = URI.parse(document.cached_attachment)
end
end
end

View File

@@ -45,7 +45,7 @@ class DocumentsController < ApplicationController
end
def destroy_upload
@document = Document.new(attachment: File.open(params[:path]))
@document = Document.new(attachment: URI.parse(params[:path]))
@document.documentable = @documentable
if @document.attachment.destroy
@@ -62,7 +62,7 @@ class DocumentsController < ApplicationController
if @document.valid?
@document.attachment_file_name = "#{Time.now.to_i} - #{@document.attachment_file_name}"
@document.attachment.save
@document.cached_attachment = @document.attachment.path
@document.cached_attachment = URI(request.url) + @document.attachment.url
else
@document.attachment.destroy
end
@@ -91,7 +91,7 @@ class DocumentsController < ApplicationController
def recover_attachments_from_cache
if @document.attachment.blank? && @document.cached_attachment.present?
@document.attachment = File.open(@document.cached_attachment)
@document.attachment = URI.parse(@document.cached_attachment)
end
end