开发者

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

开发者 https://www.devze.com 2023-02-24 20:50 出处:网络
right now, in my model of an object I have: #paperclip has_attached_file :photo,:styles => { :thumb=> \"100x100#\",

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?

Than开发者_开发技巧ks : )


You could implement a callback in the model (such as before_destroy) that makes a copy of the image before it's destroyed.

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?)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号