Reputation: 5349
I'm trying to make my application work with DELETE action without javascript.
Evrything work as long as my app/view/layout/application.html.haml file do contain the following :
!!! 5
%html
%head
%title My application
= stylesheet_link_tag 'screen', :media => 'screen, print, projection'
/[if IE]
// CSS for IE
= javascript_include_tag 'application'
= csrf_meta_tags
%body
...
If I remove the = javascript_include_tag 'application'
instruction. I can no more delete any record.
Rails is instead performing a SHOW action.
Any idea ?
Upvotes: 0
Views: 635
Reputation: 546
Ryan Bates made a nice RailsCasts episode on this issue: Destroy without JavaScript.
He simply suggests to add an extra GET member route which will lead to the same controller action when JS is disabled.
Upvotes: 1
Reputation: 7487
The only two supported methods when writing HTML forms are post
and get
. If you want to use the delete
or put
method you must use AJAX.
That is the reason why most websites use a plain post request and use a special URL. e.g.
POST /some-object/delete/
or
POST /some-object/?action=delete
Not even the latest HTML5 draft allows any other method than post
or get
: http://www.w3.org/html/wg/drafts/html/master/forms.html#attr-fs-method
Rails provides a polyfill for performing put
and delete
requests. I find this troubling especially as the code does something completely different when JavaScript is disabled.
Upvotes: 3