简体   繁体   English

删除附加到其上的对象后,如何保存回形针图像?

[英]how can I keep a paperclip image after deleting an object it is attached to?

right now, in my model of an object I have: 现在,在我的对象模型中,我有:

  #paperclip
  has_attached_file :photo,  :styles => {
  :thumb=> "100x100#",
  :small  => "150x150>",
  :medium => "300x300>",
  :large =>   "400x400>" },
  :url  => "/images/my_obj/:id/:style/:basename.:extension",
  :path => ":rails_root/public/images/my_obj/:id/:style/:basename.:extension",
  :default_url => "/images/image.png"

when I delete this item, the image gets automatically deleted as well. 当我删除此项时,图像也会自动删除。 however, I'd prefer that it remains in existence. 但是,我希望它仍然存在。 Is there a way? 有办法吗?

Thanks : ) 谢谢 : )

You could implement a callback in the model (such as before_destroy ) that makes a copy of the image before it's destroyed. 您可以在模型中实现一个回调(例如before_destroy ),该回调在销毁图像之前先对其进行复制。

Or you could just mark the item as deleted in the database instead of actually deleting it (obviously this would make it easier to restore the item if this is necessary?) 或者,您可以将项目标记为已在数据库中删除,而不是实际将其删除(很显然,如果需要的话,这将使恢复项目变得更加容易?)

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

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