{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/33362","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/33362/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/33362/comments","events_url":"https://api.github.com/repos/rails/rails/issues/33362/events","html_url":"https://github.com/rails/rails/issues/33362","id":341273160,"node_id":"MDU6SXNzdWUzNDEyNzMxNjA=","number":33362,"title":"Attachments should be detached when assigned a blank value","user":{"login":"kylefox","id":37838,"node_id":"MDQ6VXNlcjM3ODM4","avatar_url":"https://avatars2.githubusercontent.com/u/37838?v=4","gravatar_id":"","url":"https://api.github.com/users/kylefox","html_url":"https://github.com/kylefox","followers_url":"https://api.github.com/users/kylefox/followers","following_url":"https://api.github.com/users/kylefox/following{/other_user}","gists_url":"https://api.github.com/users/kylefox/gists{/gist_id}","starred_url":"https://api.github.com/users/kylefox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylefox/subscriptions","organizations_url":"https://api.github.com/users/kylefox/orgs","repos_url":"https://api.github.com/users/kylefox/repos","events_url":"https://api.github.com/users/kylefox/events{/privacy}","received_events_url":"https://api.github.com/users/kylefox/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-07-14T21:57:48Z","updated_at":"2018-07-16T03:43:22Z","closed_at":"2018-07-15T09:55:50Z","author_association":"NONE","body":"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:\r\n\r\n```ruby\r\nparams = { user: { image: 'eyJfcmF--e31aef3' } }\r\n```\r\n\r\nHowever, it's surprising that setting the attachment to an empty string does _not_ detach the attachment:\r\n\r\n```ruby\r\nparams = { user: { image: '' } } # => InvalidSignature\r\n```\r\n\r\nIt feels more Railsy to treat the empty string as a special case that detaches the attachment.\r\n\r\nThis 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.\r\n\r\nFor example, this would handle both attaching and detaching `@user.image`:\r\n\r\n```ruby\r\n@user.update_attributes(params.require(:user).permit(:name, :email, :image))\r\n```\r\n\r\n### Steps to reproduce\r\n\r\n1. Assign an attachable to the attachment: `@user.image = blob.signed_id`\r\n1. Assign an empty string to the attachment: `@user.image = ''`\r\n\r\n### Expected behavior\r\n\r\n* The attachment is detached, i.e. `@user.image.detach`.\r\n\r\n### Actual behavior\r\n\r\n* `ActiveSupport::MessageVerifier::InvalidSignature` is raised.\r\n\r\n### System configuration\r\n\r\n* **Rails version**: Rails 5.2.0\r\n* **Ruby version**: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/405143218","html_url":"https://github.com/rails/rails/issues/33362#issuecomment-405143218","issue_url":"https://api.github.com/repos/rails/rails/issues/33362","id":405143218,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTE0MzIxOA==","user":{"login":"kylefox","id":37838,"node_id":"MDQ6VXNlcjM3ODM4","avatar_url":"https://avatars2.githubusercontent.com/u/37838?v=4","gravatar_id":"","url":"https://api.github.com/users/kylefox","html_url":"https://github.com/kylefox","followers_url":"https://api.github.com/users/kylefox/followers","following_url":"https://api.github.com/users/kylefox/following{/other_user}","gists_url":"https://api.github.com/users/kylefox/gists{/gist_id}","starred_url":"https://api.github.com/users/kylefox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylefox/subscriptions","organizations_url":"https://api.github.com/users/kylefox/orgs","repos_url":"https://api.github.com/users/kylefox/repos","events_url":"https://api.github.com/users/kylefox/events{/privacy}","received_events_url":"https://api.github.com/users/kylefox/received_events","type":"User","site_admin":false},"created_at":"2018-07-16T03:43:22Z","updated_at":"2018-07-16T03:43:22Z","author_association":"NONE","body":"Here's the mailing list link if anyone is interested in continuing the discussion:\r\n\r\n* [Attachments should be detached when assigned a blank value\r\n](https://groups.google.com/forum/#!topic/rubyonrails-core/xI5HPnxIAIE)"}}
{"actor":{"display_login":"kylefox"}}