diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md index 64ad28d5d4..45d85a3d3f 100644 --- a/activestorage/CHANGELOG.md +++ b/activestorage/CHANGELOG.md @@ -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 diff --git a/activestorage/lib/active_storage/attached/many.rb b/activestorage/lib/active_storage/attached/many.rb index f0ee58bec6..90775de254 100644 --- a/activestorage/lib/active_storage/attached/many.rb +++ b/activestorage/lib/active_storage/attached/many.rb @@ -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 diff --git a/activestorage/lib/active_storage/attached/one.rb b/activestorage/lib/active_storage/attached/one.rb index 6efbfa7a54..0e3e5a9fc4 100644 --- a/activestorage/lib/active_storage/attached/one.rb +++ b/activestorage/lib/active_storage/attached/one.rb @@ -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