从 rake 任务中删除回形针附件文件
我有一个模型,其中有一个回形针附件调用电子表格。
该模型是导入,将电子表格数据导入数据库。
我想设置一个任务,可能是一个 rake 任务来清理所有旧的导入(假设超过 1 个月)。
我不确定这是否是最好的方法,但这是我在搜索时发现的。
实际的问题是,当我从 rake 任务中销毁模型时,它不会从系统中删除与附件关联的文件。另一方面,当我从 Web 应用程序中销毁模型时,它也会销毁它。
我应该如何删除附件文件并从 rake 任务中销毁模型?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该看到从控制器或从 rake 调用 #destroy 之间有任何区别。也许您混淆了#delete 和#destroy? #delete 忽略回调,因此不允许回形针清理其附件。
当然还有与文件权限相关的问题。您是否以运行网络应用程序的同一用户身份运行 rake 任务?
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?