RESTful mass deletion?

How should I implement mass deletion of records in a RESTful way? i.e.
from my index view I display a checkbox next to each record, and have
a submit button that will delete all of the checked boxes. Everything
I googled about RESTful deletion and the default destroy action is
related to destroying single records…

TIA.

I’d imagine you’d have to create a new controller method for that…
IT’s still RESTful, just not perfect.

It’s my understsanding though that it’s acceptable… just like
creating a “search” action.

You could always use Javascript helpers kinda like Ryan B. does in
his complex form example… have them all marked up for Deletion
using Ajax.

Check out this three part series.

http://railscasts.com/episodes/73
http://railscasts.com/episodes/74
http://railscasts.com/episodes/75

Just extend his example from the attribute to the whole record…
shouldn’t be too hard.

Apply a collection to the restful, destroy/delete route.

I’m at work, and I forget the details, but it is similar to adding a
member to a route.
The delete works on the whole plural collection.

I’m assuming that you want to have a UI that allows a user to select
any number of records (say with checkboxes) then have that array of
records deleted in mass. Something like messages in a Google Mail
inbox for example. So you would also want to pass in the array of ids
to the custom controller action.

I think the point to the seven base actions in a RESTful controller is
not meant to restrict the controller to only these seven. Adding your
own custom methods does not break a RESTful controller, as long as the
base actions follow the convention.

What is important is that the API you construct with your controller
makes sense to a consumer of your controller as a service. Think,
“Would this break ActiveResouce’s ability to access this controller?”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs