class Attachment
Ruby on Rails 7.2.3
Since v5.2.8.1Active Storage Attachment
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.
If you wish to preload attachments or blobs, you can use these scopes:
# preloads attachments, their corresponding blobs, and variant records (if using `ActiveStorage.track_variants`) User.all.with_attached_avatars # preloads blobs and variant records (if using `ActiveStorage.track_variants`) User.first.avatars.with_all_variant_records
Inherits from
Methods (defined here)
- # blob
- # preview
- # purge
- # purge_later
- # record
- # representation
- # variant
- self. with_all_variant_records