rails

https://github.com/rails/rails

Ruby

Ruby on Rails

ActiveStorage::Attached::One#attach

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

Source | Google | Stack overflow

Edit

git clone [email protected]:rails/rails.git

cd rails

open activestorage/lib/active_storage/attached/one.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-ActiveStorage--Attached--One-attach-for-pr


# Commit to git

git add activestorage/lib/active_storage/attached/one.rbgit commit -m "better docs for ActiveStorage::Attached::One#attach"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-ActiveStorage--Attached--One-attach-for-pr

hub pull-request


# Celebrate!