Preventing Paperclip from deleting/overwriting attachments on update

后端 未结 4 923
灰色年华
灰色年华 2020-12-30 01:39

I\'m having a hard time figuring out how to prevent Paperclip from deleting the old version of an attachment (image).

I have a model, Site, which has an attachment,

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 02:17

    lib/paperclip_monkey_patch.rb:

    module Paperclip
      class Attachment
       def clear
        # nop
        #raise "hell"
        # op
        instance_write(:file_name, nil)
        instance_write(:content_type, nil)
        instance_write(:file_size, nil)
        instance_write(:updated_at, nil)
      end
     end
    end
    

    Then add this line at the top of any file that deleted attachments:

    require 'paperclip_monkey_patch'

    Thanks to Ruby Forum

提交回复
热议问题