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?
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?)
精彩评论