lib/active_storage/attached/one.rb in activestorage-7.0.8.6 vs lib/active_storage/attached/one.rb in activestorage-7.1.0.beta1

- old
+ new

@@ -1,8 +1,10 @@ # frozen_string_literal: true module ActiveStorage + # = Active Storage \Attached \One + # # Representation of a single attachment to a model. class Attached::One < Attached ## # :method: purge # @@ -52,15 +54,14 @@ # 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 def attach(attachable) + record.public_send("#{name}=", attachable) if record.persisted? && !record.changed? - record.public_send("#{name}=", attachable) - record.save - else - record.public_send("#{name}=", attachable) + return if !record.save end + record.public_send("#{name}") end # Returns +true+ if an attachment has been made. # # class User < ApplicationRecord