Class: ActiveStorage::Attachment
- 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.
Attachments also have access to all methods from ActiveStorage::Blob.
Instance Method Summary collapse
-
#purge ⇒ Object
Synchronously deletes the attachment and purges the blob.
-
#purge_later ⇒ Object
Deletes the attachment and enqueues a background job to purge the blob.
Instance Method Details
#purge ⇒ Object
Synchronously deletes the attachment and purges the blob.
23 24 25 26 27 28 29 |
# File 'app/models/active_storage/attachment.rb', line 23 def purge transaction do delete record&.touch end blob&.purge end |
#purge_later ⇒ Object
Deletes the attachment and enqueues a background job to purge the blob.
32 33 34 35 36 37 38 |
# File 'app/models/active_storage/attachment.rb', line 32 def purge_later transaction do delete record&.touch end blob&.purge_later end |