title: Deleting a single ActiveStorage attachment out of a collection via an API call
body: <p>EDIT: <strong>TLDR</strong>: This boils down to serializing the attachments. See my response.</p>
  
  <p>I can see two ways to achieve this:</p>
  
  <p>(1) Serialize the attachments (with <code>id</code> and <code>url</code> attributes), thus providing an <code>id</code> to the FE that they can use to <code>DELETE /attachments/:id</code> which would then call <code>ActiveStorage::Attachment.find(:id).purge</code>. The problem is with serializing as attachments do not have built-in models. I tried creating an <code>ActiveStorageAttachment</code> model for the <code>active_storage_attachments</code> table but  could not get the url for the attachment as the <code>Rails.application.routes.url_helpers.url_for(@object)</code> requires an <code>ActiveStorage::Attachment</code> object not an <code>ActiveStorageAttachment</code> object.</p>
  
  <p>(2) Another option would be to have a <code>DELETE /attachments/:attachment_url</code> endpoint. For this to work, I'd need to get the <code>ActiveStorage::Attachment</code> object based on the url, in order to call <code>purge</code> on it. Not sure if that is possible?</p>
  
  <p>I'd much prefer the first solution, it feels cleaner and more adaptable. Any help with either approach would be much appreciated!</p>