title: Can't purge active storage attachments
body: <p>I have a model called Resource configured with:</p>
  
  <pre><code>class Resource &lt; ActiveRecord::Base    
  has_many_attached :assets
  end
  </code></pre>
  
  <p>I created an action in my resources_controller.rb as follows:</p>
  
  <pre><code>  def delete_asset_attachment
      @asset = ActiveStorage::Attachment.find_by(params[:id])
      logger.debug "The value of @asset is #{@asset}"
      @asset.purge
      redirect_to @resource
    end
  </code></pre>
  
  <p>I have a form that shows the resource and loops through the attached assets. Below is the snippet of code doing the loop through the assets:</p>
  
  <pre><code>&lt;% @resource.assets.each do |asset| %&gt;
  &lt;%= link_to 'Remove Attachment', delete_asset_attachment_resource_url(@resource, asset.id), method: :delete, data: { confirm: 'Are you sure?' } %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>The /resources page properly shows the resource along with the attached assets. However, when I try to click the link to delete one of the assets, I receive an error: "undefined method `purge' for nil:NilClass". However, in console I see the attachment exists. </p>
  
  <p>Here is the output from the server console:</p>
  
  <pre><code>    Started DELETE "/resources/10/delete_asset_attachment.18" for ::1 at 2019-03-09 17:27:28 -0500
  Processing by ResourcesController#delete_asset_attachment as 
    Parameters: {"authenticity_token"=&gt;"EFZO5V9Bii3dId0I6hn5DajFR5WJYZBc8qPAAi5ppQOFW3cws5I4FjyVP9IlvA+2a2kKUJhobnqd8atG4L3k+g==", "id"=&gt;"10"}
    Resource Load (0.1ms)  SELECT  "resources".* FROM "resources" WHERE "resources"."id" = ? LIMIT ?  [["id", 10], ["LIMIT", 1]]
    User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 1], ["LIMIT", 1]]
    ActiveStorage::Attachment Load (0.1ms)  SELECT  "active_storage_attachments".* FROM "active_storage_attachments" WHERE (10) LIMIT ?  [["LIMIT", 1]]
  The value of @asset is #&lt;ActiveStorage::Attachment:0x00007f8d7bd4df68&gt;
    ActiveStorage::Blob Load (0.2ms)  SELECT  "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 27], ["LIMIT", 1]]
  Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.6ms)
  
  NoMethodError - undefined method `purge' for nil:NilClass:
  
  ::1 - - [09/Mar/2019:17:27:28 EST] "POST /resources/10/delete_asset_attachment.18 HTTP/1.1" 500 76939
  http://localhost:3000/resources/10/edit -&gt; /resources/10/delete_asset_attachment.18
  Started POST "/__better_errors/70da0e976a425fce/variables" for ::1 at 2019-03-09 17:27:28 -0500
    ActiveStorage::Blob Load (0.2ms)  SELECT  "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 27], ["LIMIT", 11]]
  ::1 - - [09/Mar/2019:17:27:28 EST] "POST /__better_errors/70da0e976a425fce/variables HTTP/1.1" 200 36499
  http://localhost:3000/resources/10/delete_asset_attachment.18 -&gt; /__better_errors/70da0e976a425fce/variables
  </code></pre>
  
  <p>I've searched for solutions everywhere. The couple that exist on stackoverflow didn't address my issue. There is an incredible lack of specific details and examples in the Rails guide or anywhere else on the web for specifically handling deleting attachments. Would appreciate any help.</p>
  
  <p>UPDATE: Here are my routes.rb:</p>
  
  <p>resources :resources do
      get 'listing', :on => :collection
      put :sort, on: :collection
      member do
        delete :delete_asset_attachment
      end
    end</p>
  
  <p>UPDATE 2: rails routes output</p>
  
  <pre><code>resources GET    /resources(.:format)                                                                     resources#index
                               POST   /resources(.:format)                                                                     resources#create
                  new_resource GET    /resources/new(.:format)                                                                 resources#new
                 edit_resource GET    /resources/:id/edit(.:format)                                                            resources#edit
                      resource GET    /resources/:id(.:format)                                                                 resources#show
                               PATCH  /resources/:id(.:format)                                                                 resources#update
                               PUT    /resources/:id(.:format)                                                                 resources#update
                               DELETE /resources/:id(.:format)                                                                 resources#destroy
  </code></pre>