简体   繁体   English

从rake任务中删除回形针附件文件

[英]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. 该模型是import,它将电子表格数据导入数据库。

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). 我想设置一个任务可能是清理所有旧进口物品(例如,早于1个月)的耙任务。

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. 实际的问题是,当我从rake任务中销毁模型时,它不会从与附件关联的系统中删除文件。 On the other hand, when I destroy the model from within the web application it destroys it. 另一方面,当我从Web应用程序中破坏模型时,它也会破坏模型。

What should I do to remove the attachment files along with destroying the model from a rake task ? 我应该怎么做才能删除附件文件以及从rake任务中破坏模型?

You shouldn't see any difference between calling #destroy from your controllers or from rake. 从控制器或rake调用#destroy之间不会有任何区别。 Perhaps you're confusing #delete and #destroy? 也许您会混淆#delete和#destroy? #delete ignores callbacks and therefore won't allow paperclip to clean up its attachments. #delete会忽略回调,因此将不允许回形针清理其附件。

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? 您是否以与运行Web应用程序相同的用户身份运行rake任务?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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