Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

use after_commit instead of after_destroy for removing attached files? #1020

Closed
xxx opened this issue Sep 17, 2012 · 3 comments
Closed

use after_commit instead of after_destroy for removing attached files? #1020

xxx opened this issue Sep 17, 2012 · 3 comments

Comments

@xxx
Copy link

xxx commented Sep 17, 2012

Hello,

I noticed that attachments are being removed in an after_destroy callback, which runs within the database transaction, but doesn't seem to need to. ActiveRecord 3.0 added after_commit as a callback, which runs after the transaction completes successfully, and seems to be more appropriate for this situation.

As of now, I'm patching around with the following to do this:

has_attached_file blah blah

skip_callback, :destroy, :after, :destroy_attached_files
after_commit :destroy_attached_files, :on => :destroy

which is working fine. Is there a reason it shouldn't be done this way, that I'm not aware of?

@tute
Copy link
Contributor

tute commented May 9, 2015

@xxx, is this still an issue with paperclip for you?

@xxx
Copy link
Author

xxx commented May 9, 2015

Looks like 3.x and 4.x are using after_commit now. I'll close this out.

@xxx xxx closed this as completed May 9, 2015
@tute
Copy link
Contributor

tute commented May 9, 2015

Thanks for your report, and sorry for the very late response!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants