防止 Paperclip 在更新时删除/覆盖附件 [英] Preventing Paperclip from deleting/overwriting attachments on update

查看:40
本文介绍了防止 Paperclip 在更新时删除/覆盖附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难弄清楚如何防止 Paperclip 删除旧版本的附件(图像).

I'm having a hard time figuring out how to prevent Paperclip from deleting the old version of an attachment (image).

我有一个模型 Site,它有一个附件和徽标.我想保留旧徽标,因为我将跟踪模型的更改并希望查看徽标的历史.

I have a model, Site, which has an attachment, logo. I would like to keep the old logos around since I will be keeping track of changes to the model and would like to view the history of logos.

我正在跟踪另一个模型中的更改,该模型引用了文件路径.我的问题是,当使用新徽标更新网站时,Paperclip 会先刷新旧徽标.

I'm keeping track of the changes in another model, which has a reference to file paths. My problem is that when updating a site with a new logo, Paperclip will flush the old logo first.

令我惊讶的是,您无法切换到防止 Paperclip 在创建新附件之前刷新旧附件的选项.

It surprises me that there's not an option you can switch to prevent Paperclip from flushing the old attachment before creating the new one.

有什么想法吗?

推荐答案

有一个新选项可以告诉回形针保留旧附件:

There's a new option that tells paperclip to preserve old attachments:

https://github.com/thoughtbot/paperclip/commit/65e8d4f6de50732d8e1bhttps://github.com/thoughtbot/paperclip/issues/60

使用简单:

has_attached_file => :attachment,
                     :styles => { :thumb => 100x100! },
                     :preserve_files => true

它还没有被记录下来,需要进行一些挖掘才能找到,所以我想在这里分享.

It's not documented yet and took some digging to find so I wanted to share it here.

这篇关于防止 Paperclip 在更新时删除/覆盖附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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