I implemented the code for removing images from my User
model.
Rails 5.2 Active Storage purging/deleting attachements
I think that it removed the image OK, but now I'm getting an error
undefined method `signed_id' for nil:NilClass
My view (images.html.erb
):
<% if @user.images.attached? %>
<% @user.images.each do |image| %>
<%= image_tag(url_for(image))%>
<%= link_to 'Remove', delete_image_attachment_user_url(image.signed_id),
method: :delete,
data: { confirm: 'Are you sure?' } %>
<% end %>
<% end %>
The controller
def images
end
def delete_image_attachment
@image = ActiveStorage::Blob.find_signed(params[:id])
@image.purge
redirect_to root_path
end
I tried removing code from the view, so it just has this:
<% if @user.images.attached? %>
<% @user.images.each do |image| %>
<%= image_tag(url_for(image))%>
<% end %>
<% end %>
But even after I remove the code for 'signed_id', I still receive the error. Also, I'm unsure why it looks at the line receiving the code:
<%= image_tag(url_for(image))%>
if I'm using when I have the line
@user.images.attached?
I thought the error might be that there were no attached images (although there should be one attached), so I added that check.
来源:https://stackoverflow.com/questions/51085012/rails-5-2-activestorage-undefined-method-signed-id-for-nilnilclass