ruby-on-railsrestunobtrusive-javascriptlink-to-remote

How do I get a Rails link_to_remote tag to make a DELETE request when JavaScript is disabled?


I'm using the following code as a link to delete a todo in a simple todo list application I'm making:

<%= link_to_remote 'delete', {:url => complete_todo, :confirm => 'Are you sure?', :method => :delete}, { :href => url_for(complete_todo), :method => :delete } %>

It works fine when JavaScript is enabled, but when it's disabled it makes a GET request to the server instead of the expected DELETE request, and therefore links to the todo's show page instead of destroying it.

Because I'm trying to keep the application as RESTful as possible, I don't want to add a route to allow the destroy action to be run using a GET request.

Any ideas what I'm doing wrong?


Solution

  • As ever, Ryan Bates comes to the rescue with a Railscast: Destroy Without JavaScript.