class ActiveStorage::Attached::Many
def attach(*attachables)
document.images.attach(io: File.open("/path/to/racecar.jpg"), filename: "racecar.jpg", content_type: "image/jpeg")
document.images.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload
document.images.attach(params[:images]) # Array of ActionDispatch::Http::UploadedFile objects
record is next saved.
the database immediately. Otherwise, they'll be saved to the DB when the
If the record is persisted and unchanged, the attachments are saved to
Attaches one or more +attachables+ to the record.
def attach(*attachables) if record.persisted? && !record.changed? record.public_send("#{name}=", blobs + attachables.flatten) record.save else record.public_send("#{name}=", (change&.attachables || blobs) + attachables.flatten) end end