aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activestorage/lib')
-rw-r--r--activestorage/lib/active_storage/attached/one.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activestorage/lib/active_storage/attached/one.rb b/activestorage/lib/active_storage/attached/one.rb
index 0244232b2c..e3600dc241 100644
--- a/activestorage/lib/active_storage/attached/one.rb
+++ b/activestorage/lib/active_storage/attached/one.rb
@@ -64,12 +64,16 @@ module ActiveStorage
private
def replace(attachable)
- blob.tap do
+ unless attachable == blob
+ previous_blob = blob
+
transaction do
detach
write_attachment build_attachment_from(attachable)
end
- end.purge_later
+
+ previous_blob.purge_later
+ end
end
def build_attachment_from(attachable)