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
.
Methods
Instance Public methods
purge()
Synchronously deletes the attachment and purges the blob.
๐ Source code
# File activestorage/app/models/active_storage/attachment.rb, line 23
def purge
transaction do
delete
record&.touch
end
blob&.purge
end
๐ See on GitHub
purge_later()
Deletes the attachment and enqueues a background job to purge the blob.
๐ Source code
# File activestorage/app/models/active_storage/attachment.rb, line 32
def purge_later
transaction do
delete
record&.touch
end
blob&.purge_later
end
๐ See on GitHub