class ActiveStorage::Attached::One

def attach(attachable)

person.avatar.attach(avatar_blob) # ActiveStorage::Blob object
person.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpg")
person.avatar.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload
person.avatar.attach(params[:avatar]) # ActionDispatch::Http::UploadedFile object

Associates a given attachment with the current record, saving it to the database.
def attach(attachable)
  blob_was = blob if attached?
  blob = create_blob_from(attachable)
  unless blob == blob_was
    transaction do
      detach
      write_attachment build_attachment(blob: blob)
    end
    blob_was.purge_later if blob_was && dependent == :purge_later
  end
end