简体   繁体   中英

Delete paperclip attachment files from a rake task

I have a model which has a paperclip attachment call spreadsheet.

The model is import which imports a spreadsheet data into the database.

I want to setup a task may be a rake task to clean up all the old imports (let's say older than 1 month).

I am not sure if this is the best way but this is what I found while searching.

The actual question is, when I destroy the model from a rake task, it doesn't delete the file from the system which is associated with the attachment. On the other hand, when I destroy the model from within the web application it destroys it.

What should I do to remove the attachment files along with destroying the model from a rake task ?

You shouldn't see any difference between calling #destroy from your controllers or from rake. Perhaps you're confusing #delete and #destroy? #delete ignores callbacks and therefore won't allow paperclip to clean up its attachments.

Of course there's also issues related to file permissions. Are you running the rake task as the same user that runs the app for the web?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM