I have created a delete link in the view to delete an object using link_to in Rails but whenever i click the link it goes to the :show method instead of prompting a Javascript alert box for delete confirmation. Here is the code in the view.
...
<%= link_to "delete", service, :method => :delete,
:confirm => "You sure?",
:title => service.title %>
...
I have configured the routes in config/routes.rb and i am sure the Delete route exists as i have checked with the rake routes command. So what did i miss?
Finally, i found that i didn’t include the default Rails Javascript files. The problem was solved by adding the following line inside the <head> in application.html.erb.
- <%= javascript_include_tag :defaults %>
The delete link works perfect now.
Done =)
Reference: Stack Overflow – link_to delete url is not working
