如何防止回形针从 act_as_paranoid 模型中删除附件? [英] How do I keep paperclip from deleting attachments from an acts_as_paranoid model?

查看:38
本文介绍了如何防止回形针从 act_as_paranoid 模型中删除附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型,其中包含由回形针管理的几个不同的图像附件.最近我们改变了模型的行为,所以它可以被软删除并使用 act_as_paranoid 恢复.一切正常,除了当我们软删除模型时,回形针也会删除附件.

我已经浏览了回形针文档和代码,但我没有看到明显的方法来规避这一点.我希望能够告诉回形针忽略模型上的删除回调并保留附件?

解决方案

Paperclip 现在有一个 preserve_files 选项.现在不需要覆盖.

<块引用>

用于软删除的文件保留

有一个选项可以保留附件,以便与软删除模型很好地配合.(acts_as_paranoid、paranoia 等)

has_attached_file :some_attachment, {:preserve_files =>真",}

<块引用>

这样可以防止 some_attachment 在模型被销毁时被清除掉,所以在稍后恢复对象时它仍然存在.

https://github.com/thoughtbot/paperclip#file-软删除保留

I have a model with a couple of different image attachments managed by paperclip. Recently we changed the behavior of the model so it could be soft-deleted and revived using acts_as_paranoid. Everything works great except that when we soft delete the model, paperclip is deleting the attachments as well.

I've looked through the paperclip docs and the code and I don't see an obvious way to circumvent this. I'd like to be able to tell paperclip to ignore the delete callbacks on the model and keep the attachments around?

解决方案

Paperclip now has a preserve_files option. Override shouldn't be necessary now.

File Preservation for Soft-Delete

An option is available to preserve attachments in order to play nicely with soft-deleted models. (acts_as_paranoid, paranoia, etc.)

has_attached_file :some_attachment, {
  :preserve_files => "true",
}

This will prevent some_attachment from being wiped out when the model gets destroyed, so it will still exist when the object is restored later.

https://github.com/thoughtbot/paperclip#file-preservation-for-soft-delete

这篇关于如何防止回形针从 act_as_paranoid 模型中删除附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆