instance method
attach
Ruby on Rails 5.2.8.1
Since v5.2.8.1Signature
attach(*attachables)
Associates one or several attachments with the current record, saving them to the database.
document.images.attach(params[:images]) # Array of ActionDispatch::Http::UploadedFile objects document.images.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload document.images.attach(io: File.open("/path/to/racecar.jpg"), filename: "racecar.jpg", content_type: "image/jpg") document.images.attach([ first_blob, second_blob ])
Parameters
-
attachablesrest
Source
# File activestorage/lib/active_storage/attached/many.rb, line 21
def attach(*attachables)
attachables.flatten.collect do |attachable|
if record.new_record?
attachments.build(record: record, blob: create_blob_from(attachable))
else
attachments.create!(record: record, blob: create_blob_from(attachable))
end
end
end
Defined in activestorage/lib/active_storage/attached/many.rb line 21
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveStorage::Attached::Many