问题
A while back I tried to delete attachments of the active storage so I follow the answer of this question: Rails 5.2 Active Storage purging/deleting attachements
But after doing this:
def delete_image_attachment
@image = ActiveStorage::Blob.find_signed(params[:id])
@image.purge
redirect_to collections_url
end
I start getting this error every time I entered a view with images or a link to the destroy method:
So I change the code a bit:
routes.rb
match 'vehicles/:id/:image_id' => 'vehicles#delete_image_attachment', :via => :delete, :as => :delete_image_attachment
vehicles_controller.rb
def delete_image_attachment
@image = ActiveStorage::Attachment.find(params[:image_id])
@image.purge
redirect_back(fallback_location: vehicles_path)
end
in a view that I want to delete some image
<% @vehicle.images.each do |img| %>
<%= image_tag img %>
<%= link_to delete_image_attachment_url(@vehicle, img), method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
That kind of works for the vehicles that already existed, but when I create a new vehicle the same error appears in every view with an image of that vehicle.
Does anyone knows what kind of error is this, and how can I fix it? Also, there is any way to delete all data from active storage, like resetting the table? Thank you!
来源:https://stackoverflow.com/questions/51170577/undefined-method-signed-id-for-nilnilclass