Here is my rails link_to
<%= link_to 'Delete',url_for(action: :delete,id: @user.id),data: {confirm: "Are you sure?"} %>
I tried the above method but it is directly deleting without any alert message. What wrong I made. Can any one correct it.
Try this
<%= link_to 'Delete',url_for(action: :delete,id: @user.id),method: :delete, data: {confirm: "Are you sure?"} %>
                        Answer for rails 4.1.8 (question doesn't include version)
and standard resource (also not specified)
//= jquery_ujs   must be included in application.js (possibly missing)user_path(@user)    :method => :delete  (missing):data (was good)= link_to t(:delete) , user_path(@user), :method => :delete, :class => "btn btn-danger", :data => {:confirm => t(:are_you_sure )}
The url in the question seems to create a GET, rather than a DELETE method. This may work if :method was specified. imho it is unfortunate that there is no seperate named url helper for this.
<%= link_to 'Delete', url_for(action: :delete, id: @user.id),
  method: :delete, data: {confirm: "Are you sure?"} %>
<%= link_to 'Delete', url_for(action: :delete, id: @user.id),
  data: {turbo_method: :delete, turbo_confirm: 'Are you sure?'} %>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With