instance method attach!

Ruby on Rails edge

Since edge

Signature

attach!(attachable)

Calls attach, and raises an exception if the record was meant to be saved but at least one of the validations failed.

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("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpeg")
person.avatar.attach!(avatar_blob) # ActiveStorage::Blob object

Parameters

attachable req
Source
# File activestorage/lib/active_storage/attached/one.rb, line 78
    def attach!(attachable)
      attach(attachable) || raise(ActiveRecord::RecordNotSaved.new("Failed to save the record", record))
    end

Defined in activestorage/lib/active_storage/attached/one.rb line 78 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveStorage::Attached::One

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close