Skip to content

Commit

Permalink
Merge pull request #31652 from kami-zh/activestorage-callbacks
Browse files Browse the repository at this point in the history
Change Active Storage destroy callbacks
  • Loading branch information
georgeclaghorn committed Jan 9, 2018
2 parents 428939b + 9431529 commit baa88b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions activestorage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Use `after_destroy_commit` instead of `before_destroy` for purging
attachments when a record is destroyed.

*Hiroki Zenigami*


* Force `:attachment` disposition for specific, configurable content types.
This mitigates possible security issues such as XSS or phishing when
serving them inline. A list of such content types is included by default,
Expand Down
4 changes: 2 additions & 2 deletions activestorage/lib/active_storage/attached/macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def #{name}=(attachable)
scope :"with_attached_#{name}", -> { includes("#{name}_attachment": :blob) }

if dependent == :purge_later
before_destroy { public_send(name).purge_later }
after_destroy_commit { public_send(name).purge_later }
end
end

Expand Down Expand Up @@ -89,7 +89,7 @@ def #{name}=(attachables)
scope :"with_attached_#{name}", -> { includes("#{name}_attachments": :blob) }

if dependent == :purge_later
before_destroy { public_send(name).purge_later }
after_destroy_commit { public_send(name).purge_later }
end
end
end
Expand Down

0 comments on commit baa88b8

Please sign in to comment.