Class: ActiveStorage::Attachment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActiveStorage::Attachment
- Includes:
- ActiveModel::ForbiddenAttributesProtection
- 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. If you’re doing that, you’ll want to declare with ‘has_one/many_attached :thingy, dependent: false`, so that destroying any one record won’t destroy the blob as well. (Then you’ll need to do your own garbage collecting, though).
Instance Method Summary collapse
-
#purge ⇒ Object
Purging an attachment will purge the blob (delete the file on the service, then destroy the record) and then destroy the attachment itself.
-
#purge_later ⇒ Object
Purging an attachment means purging the blob, which means talking to the service, which means talking over the internet.
Instance Method Details
#purge ⇒ Object
Purging an attachment will purge the blob (delete the file on the service, then destroy the record) and then destroy the attachment itself.
22 23 24 25 |
# File 'app/models/active_storage/attachment.rb', line 22 def purge blob.purge destroy end |
#purge_later ⇒ Object
Purging an attachment means purging the blob, which means talking to the service, which means talking over the internet. Whenever you’re doing that, it’s a good idea to put that work in a job, so it doesn’t hold up other operations. That’s what #purge_later provides.
30 31 32 |
# File 'app/models/active_storage/attachment.rb', line 30 def purge_later ActiveStorage::PurgeAttachmentWorker.perform_async(self.id) end |