views:

384

answers:

2

I have a model that is using Paperclip to manage the file.

After I delete the model, I obviously would like the file to be deleted as well, but I cannot seem to find out how to get the file deleted using Paperclip.

I have tried self.sourcefile = nil if !sourcefile.dirty? in the before_destroy def, but that had no effect.

(I want to be able to have it delete the file locally when I test, and then on S3 when I use that - So i need a pure paperclip solution)

Any ideas?

A: 

I may be wrong but I believe it should do it automatically since has_attached_file adds a before_destroy callback. Source.

Edit: If it's not working, maybe you could try calling destroy_attached_files yourself, which would seem weird to me. Source.

theIV
I am using that, but my files still remain. :(
webdestroya
very bizarre. The only other thing I can think of is opening up an issue :/ http://github.com/thoughtbot/paperclip/issues
theIV
@theIV - Yea, it's really frustrating. I've tried calling `destroy_attached_files` to no avail. The files still sit there. I might just abandon paperclip
webdestroya
I hear the frustration, though, I find paperclip to be one of the best options for file attachments out there. Then again, I've never had this issue :/
theIV
+1  A: 

Paperclip is pretty noisy when it fails to delete a file.

Without any special configuration, when you delete an object, the associated files, if any, are deleted too, and this is noted in the log (at least in development mode):

[paperclip] Deleting attachments.
[paperclip] deleting /clipper/public/system/avatars/3/original/whatever.JPG

If Paperclip is unable to delete the file, it will simply throw an exception.

All this was tested with the latest Paperclip (cloned from github on May 25th). If you have an older version you might want to update it, then run some tests while watching the logs.

Roadmaster
Yea, I can see it saying that in the logs, but it just never reflected on my filesystem, so I just opted to use straight AWS access, as paperclip also didn't quite work (regardless of the file deletion thing)
webdestroya