Skip to content

Commit fbfb6e6

Browse files
committed
Return blob/blobs when #attach is able to save the record and return if it is not able to
1 parent 49b4af8 commit fbfb6e6

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

activestorage/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
* Saving attachment(s) to a record returns the blob/blobs object
2+
3+
Previously, saving attachments did not return the blob/blobs that
4+
were attached. Now, saving attachments to a record with `#attach`
5+
method returns the blob or array of blobs that were attached to
6+
the record. If it fails to save the attachment(s), then it returns
7+
`false`.
8+
9+
*Ghouse Mohamed*
10+
111
* Don't stream responses in redirect mode
212

313
Previously, both redirect mode and proxy mode streamed their

activestorage/lib/active_storage/attached/many.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ def blobs
4949
def attach(*attachables)
5050
if record.persisted? && !record.changed?
5151
record.public_send("#{name}=", blobs + attachables.flatten)
52-
return record.public_send("#{name}") if record.save
53-
false
52+
if record.save
53+
record.public_send("#{name}")
54+
else
55+
false
56+
end
5457
else
5558
record.public_send("#{name}=", (change&.attachables || blobs) + attachables.flatten)
5659
end

activestorage/lib/active_storage/attached/one.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ def blank?
5656
def attach(attachable)
5757
if record.persisted? && !record.changed?
5858
record.public_send("#{name}=", attachable)
59-
return record.public_send("#{name}") if record.save
60-
false
59+
if record.save
60+
record.public_send("#{name}")
61+
else
62+
false
63+
end
6164
else
6265
record.public_send("#{name}=", attachable)
6366
end

0 commit comments

Comments
 (0)