From 7e658588fa15e799614268f1f733946bf2ef26cd Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sun, 4 Mar 2018 18:54:12 -0500 Subject: Handle another case where a blob might be erroneously purged --- activestorage/lib/active_storage/attached/one.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'activestorage/lib/active_storage/attached/one.rb') diff --git a/activestorage/lib/active_storage/attached/one.rb b/activestorage/lib/active_storage/attached/one.rb index e3600dc241..008f5a796b 100644 --- a/activestorage/lib/active_storage/attached/one.rb +++ b/activestorage/lib/active_storage/attached/one.rb @@ -64,20 +64,25 @@ module ActiveStorage private def replace(attachable) - unless attachable == blob - previous_blob = blob + blob_was = blob + blob = create_blob_from(attachable) + unless blob == blob_was transaction do detach - write_attachment build_attachment_from(attachable) + write_attachment build_attachment(blob: blob) end - previous_blob.purge_later + blob_was.purge_later end end def build_attachment_from(attachable) - ActiveStorage::Attachment.new(record: record, name: name, blob: create_blob_from(attachable)) + build_attachment blob: create_blob_from(attachable) + end + + def build_attachment(blob:) + ActiveStorage::Attachment.new(record: record, name: name, blob: blob) end def write_attachment(attachment) -- cgit v1.2.3