Skip to content

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

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

2 participants

@xxx
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
thoughtbot, inc. member
tute commented May 9, 2015

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

@xxx
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 May 9, 2015
@tute
thoughtbot, inc. member
tute commented May 9, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.