简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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