diff options
Diffstat (limited to 'lib/active_storage/attached/one.rb')
-rw-r--r-- | lib/active_storage/attached/one.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/active_storage/attached/one.rb b/lib/active_storage/attached/one.rb index d255412842..0c522e856e 100644 --- a/lib/active_storage/attached/one.rb +++ b/lib/active_storage/attached/one.rb @@ -10,14 +10,19 @@ class ActiveStorage::Attached::One < ActiveStorage::Attached record.public_send("#{name}_attachment") end - # Associates a given attachment with the current record, saving it to the - # database. + # Associates a given attachment with the current record, saving it to the database. + # Examples: + # + # person.avatar.attach(params[:avatar]) # ActionDispatch::Http::UploadedFile object + # person.avatar.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload + # person.avatar.attach(io: File.open("~/face.jpg"), filename: "face.jpg", content_type: "image/jpg") + # person.avatar.attach(avatar_blob) # ActiveStorage::Blob object def attach(attachable) write_attachment \ ActiveStorage::Attachment.create!(record: record, name: name, blob: create_blob_from(attachable)) end - # Checks the presence of the attachment. + # Returns true if an attachment has been made. # # class User < ActiveRecord::Base # has_one_attached :avatar |