[LRUG] REST and Delete without JavaScript

Alex Young alex at blackkettle.org
Fri Mar 27 04:55:04 PDT 2009

Simon Sebright wrote:
> Hi,
> Perhaps this is already well-known.  I am fairly new to Rails and am 
> working on an app which uses a RESTful style.  I want to offer Delete 
> options for the various objects and have first done this with the 
> link_to function with :method => :delete.
> However, with JavaScript turned off, this is just a link to the 
> "showing" of an object.
> Now, I know it is not a good idea simply to have a fixed GET link to 
> delete something, but want to offer a solution that works both with and 
> without JavaScript enabled on the Client Browser.  Is there an 
> established idiom for this?
> I guess the non-JS case needs a form with a POST action, which could 
> work just as well with JS via Ajax.  Then it seems a shame to have 
> bypassed the lovely :method => :delete!

Behind the scenes, the JS that :method => :delete generates is just POSTing a 
form with a "_method" => "delete" parameter. button_to does the same with an 
explicit, literal form. I'd use that.


More information about the Chat mailing list