[LRUG] REST and Delete without JavaScript

Simon Sebright simonsebright at hotmail.com
Fri Mar 27 07:45:23 PDT 2009

From: "Tom Armitage" <tom at infovore.org>
Sent: Friday, March 27, 2009 1:55 PM
To: "London Ruby Users Group" <chat at lists.lrug.org>
Subject: Re: [LRUG] REST and Delete without JavaScript

> 2009/3/27 Simon Sebright <simonsebright at hotmail.com>:
>> 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!
>> Any pointers?
> My approach tends to be: just as you have pairings of new/create,
> edit/update , you also need a pairing of delete/destroy.
> So: in your routes, you add a :member route:
> map.resources :forums, :member => {:delete => :get}
> and your delete controller simply renders an "are you sure?" form. That 
> form:
> <% form_for :message, :html => { :method => :delete }, :url =>
> forum_path(@forum) do |f| -%>
> <p class="submit"><%= submit_tag "Delete forum" %></p>
> <% end -%>
> You still end up calling forums#destroy with a DELETE HTTP method, you
> just have an interstitial delete view first.
> It always annoys me that rails doesn't generate a "delete" view to
> pair with "destroy"; to my mind, this is the only right way to do it.
> Once this is in place, making it happen automagically via js is easy.

Thanks to all for the ideas.  I like the confirmation aspect which works 
without JS.

More information about the Chat mailing list