Skip to content

Commit 49b4af8

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

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

activestorage/lib/active_storage/attached/many.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def blobs
4949
def attach(*attachables)
5050
if record.persisted? && !record.changed?
5151
record.public_send("#{name}=", blobs + attachables.flatten)
52-
record.save
52+
return record.public_send("#{name}") if record.save
53+
false
5354
else
5455
record.public_send("#{name}=", (change&.attachables || blobs) + attachables.flatten)
5556
end

activestorage/lib/active_storage/attached/one.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def blank?
5656
def attach(attachable)
5757
if record.persisted? && !record.changed?
5858
record.public_send("#{name}=", attachable)
59-
record.save
59+
return record.public_send("#{name}") if record.save
60+
false
6061
else
6162
record.public_send("#{name}=", attachable)
6263
end

0 commit comments

Comments
 (0)