When I use link_to :method=>:delete, what rails has generated is a javascript click, which is not nice if you do come across situation your client just have javascript disabled. That seems a bad idea to me. Any chance to get around this?
What it generates is a form with method="delete", your best bet is to make the form yourself, the only thing is that the submit button won't be a link, but a button.
You should not, by any mean, try to do it with a basic <a href="">
, because a disruptive action (create, update, delete) should not be made with a GET
request.
Your only other option is to do it manually.
Assuming the object you want to delete is in @item, just do this:
form_for @item, :method => :delete do |f|
f.submit "Delete this item"
end
Then you can style the submit button to make it look like a normal link, if you want.
If you need it to work without JavaScript use button_to
:
<%= button_to 'Delete', @item, :method => :delete %>
From the doc:
Generates a form containing a single button that submits to the URL created by the set of +options+. This is the safest method to ensure links that cause changes to your data are not triggered by search bots or accelerators.