views:

893

answers:

1

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? Thanks in advance!

+2  A: 

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

John Topley
Thanks! I don't know why I keep forgetting about Railscasts, and it's a shame his screencasts don't seem to rank very high in Google.
Grant Heaslip