aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activestorage/lib')
-rw-r--r--activestorage/lib/active_storage/attached/model.rb22
1 files changed, 4 insertions, 18 deletions
diff --git a/activestorage/lib/active_storage/attached/model.rb b/activestorage/lib/active_storage/attached/model.rb
index 287c7a9253..1cdaac2e32 100644
--- a/activestorage/lib/active_storage/attached/model.rb
+++ b/activestorage/lib/active_storage/attached/model.rb
@@ -53,6 +53,8 @@ module ActiveStorage
after_save { attachment_changes[name.to_s]&.save }
+ after_commit(on: %i[ create update ]) { attachment_changes.delete(name.to_s).try(:upload) }
+
ActiveRecord::Reflection.add_attachment_reflection(
self,
name,
@@ -117,6 +119,8 @@ module ActiveStorage
after_save { attachment_changes[name.to_s]&.save }
+ after_commit(on: %i[ create update ]) { attachment_changes.delete(name.to_s).try(:upload) }
+
ActiveRecord::Reflection.add_attachment_reflection(
self,
name,
@@ -125,26 +129,8 @@ module ActiveStorage
end
end
- def committed!(*) #:nodoc:
- unless destroyed?
- upload_attachment_changes
- clear_attachment_changes
- end
-
- super
- end
-
def attachment_changes #:nodoc:
@attachment_changes ||= {}
end
-
- private
- def upload_attachment_changes
- attachment_changes.each_value { |change| change.try(:upload) }
- end
-
- def clear_attachment_changes
- @attachment_changes = {}
- end
end
end