[LRUG] REST and Delete without JavaScript

Tom Armitage tom at infovore.org
Fri Mar 27 05:55:07 PDT 2009

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.


More information about the Chat mailing list