I am using Administrate gem version 0.16.0 and my Rails version is 6.1.3.1
In the listing of my records, I have a trash icon on click of which record should be deleted. But somehow it sends a GET request and goes into show action of the controller instead of deleting.
I know there are similar kinds of questions on Stackoverflow but I am not able to find one in which they are using a span tag or anything to have a delete symbol inside link_to.
Following is my code :
<td><% if valid_action? :destroy, collection_presenter.resource_name %><%= link_to(
[namespace, resource],
class: "text-color-red",
method: :delete,
data: { confirm: "This alert contains #{resource.alert_details.count} alert details. Are you sure you want to delete it?" },
title: "Delete",
) do %>
<span class="material-icons">
delete
</span>
<% end if show_action? :destroy, resource %>
<% end %></td>
Till now I have tried removing confirm dialog and see that it worked properly. But I wanted to keep the confirmation dialog. Then I tried to remove the span tag and added only the text "delete" and it worked. So basically with the span tag, it has some issues and it's not sending delete requests.
I don't need to add rails-ujs because it's already there in the application.js package due to my rails version which is 6.1.
Also, I have tried button_to but still it's not working.
HTML rendered for this code is as follows:
<a class="text-color-red" data-confirm="This alert contains 0 alert details. Are you sure you want to delete it?" data-turbo-method="delete" title="Delete" rel="nofollow" data-method="delete" href="/admin/alerts/67">
<span class="material-icons">
delete
</span>
</a>