Rails – link_to :delete fails

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.