-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Closed
Description
ActiveStorage allows attachments to be attached by assigning a string representing a blob's signed_id
. This works brilliantly because it enables the same params
conventions used when assigning other attributes through forms → controllers → models:
params = { user: { image: 'eyJfcmF--e31aef3' } }
However, it's surprising that setting the attachment to an empty string does not detach the attachment:
params = { user: { image: '' } } # => InvalidSignature
It feels more Railsy to treat the empty string as a special case that detaches the attachment.
This would allow attachments to be removed in a way that mirrors how they are added (i.e. posting hidden field values) instead of having to call @user.image.detach
in a controller.
For example, this would handle both attaching and detaching @user.image
:
@user.update_attributes(params.require(:user).permit(:name, :email, :image))
Steps to reproduce
- Assign an attachable to the attachment:
@user.image = blob.signed_id
- Assign an empty string to the attachment:
@user.image = ''
Expected behavior
- The attachment is detached, i.e.
@user.image.detach
.
Actual behavior
ActiveSupport::MessageVerifier::InvalidSignature
is raised.
System configuration
- Rails version: Rails 5.2.0
- Ruby version: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
chrismitchell, jasoncharnes, twitnithegirl, maxencehenneron, basilkhan05 and 1 more
Metadata
Metadata
Assignees
Labels
No labels