Merge pull request #44439 from ghousemohamed/patch-6

Return the blob/blobs when #attach is able to save the record
This commit is contained in:
Rafael Mendonça França 2022-02-25 16:19:01 -05:00 committed by GitHub
commit fb88db58d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -1,3 +1,13 @@
* Saving attachment(s) to a record returns the blob/blobs object
Previously, saving attachments did not return the blob/blobs that
were attached. Now, saving attachments to a record with `#attach`
method returns the blob or array of blobs that were attached to
the record. If it fails to save the attachment(s), then it returns
`false`.
*Ghouse Mohamed*
* Don't stream responses in redirect mode
Previously, both redirect mode and proxy mode streamed their

View File

@ -49,7 +49,11 @@ module ActiveStorage
def attach(*attachables)
if record.persisted? && !record.changed?
record.public_send("#{name}=", blobs + attachables.flatten)
record.save
if record.save
record.public_send("#{name}")
else
false
end
else
record.public_send("#{name}=", (change&.attachables || blobs) + attachables.flatten)
end

View File

@ -56,7 +56,11 @@ module ActiveStorage
def attach(attachable)
if record.persisted? && !record.changed?
record.public_send("#{name}=", attachable)
record.save
if record.save
record.public_send("#{name}")
else
false
end
else
record.public_send("#{name}=", attachable)
end