aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-07-13 06:33:45 -0400
committerGeorge Claghorn <george@basecamp.com>2018-07-13 06:33:45 -0400
commit63951072afc371e1393f3e185bee72e1bdcfdcfe (patch)
tree90b792a33b974ac70701ef10232de2d421154894 /activestorage/lib
parentac2ada3e00247c1525257b8d56b2e8660d586f11 (diff)
downloadrails-63951072afc371e1393f3e185bee72e1bdcfdcfe.tar.gz
rails-63951072afc371e1393f3e185bee72e1bdcfdcfe.tar.bz2
rails-63951072afc371e1393f3e185bee72e1bdcfdcfe.zip
Fix analyzing new blobs from uploaded files on attach
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