Paperclip::Attachment#clear . Paperclip::Attachment#queue_all_for_delete.
, Paperclip :preserve_files, , , , .
, #queue_all_for_delete - , . , . , , .
So, I ended up with this module, which embeds itself in the method search path and selectively defines or cancels the no-op override for #queue_all_for_delete:
module PaperclipKeepAttachment
def self.with_patch
patch
add_override
yield
ensure
remove_override
end
def self.patch
me = self
Paperclip::Attachment.class_eval{ prepend me } unless Paperclip::Attachment.ancestors.include?(me)
end
def self.add_override
define_method(:queue_all_for_delete) do
end
end
def self.remove_override
remove_method(:queue_all_for_delete)
end
end
With it you can do something like:
PaperclipKeepAttachment.with_patch do
first_record.destroy
end
second_record.destroy
Amita source
share