ruby-on-railsrubyamazon-s3dragonfly-gem

Leave attachment on storage (S3) when destroying a Dragonfly object


I have a rails model, which has a dragonfly attachment, stored on S3. Do you know how to configure dragonfly, so if you delete the rails object, the attachment itself would not be deleted automatically, but left in the storage?


Solution

  • Okay, I found out. This User model will handle photos, but if a user is destroyed, it won't delete the actual photo attachments from the storage.

    class User < ActiveRecord::Base  # model
      dragonfly_accessor :photo
    
      skip_callback :destroy, :before, :destroy_dragonfly_attachments
    end