Class: ActiveStorage::Attachment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/active_storage/attachment.rb

Overview

Attachments associate records with blobs. Usually that's a one record-many blobs relationship, but it is possible to associate many different records with the same blob. A foreign-key constraint on the attachments table prevents blobs from being purged if they’re still attached to any records.

Instance Method Summary collapse

Instance Method Details

#purgeObject

Synchronously deletes the attachment and purges the blob.



20
21
22
23
# File 'app/models/active_storage/attachment.rb', line 20

def purge
  delete
  blob&.purge
end

#purge_laterObject

Deletes the attachment and enqueues a background job to purge the blob.



26
27
28
29
# File 'app/models/active_storage/attachment.rb', line 26

def purge_later
  delete
  blob&.purge_later
end