# RESTful mass deletion?

**URL:** <https://www.ruby-forum.com/t/restful-mass-deletion/136179>\
**Category:** Rails\
**Created:** [April 29, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/restful-mass-deletion/136179 "2008-04-29T17:20:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_LupiSSS\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@Juan\_LupiSSS\_n](https://www.ruby-forum.com/u/Juan_LupiSSS_n)\
**Post date:** [April 29, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/restful-mass-deletion/136179/1 "2008-04-29T17:20:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Juan\_LupiSSS\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@Juan\_LupiSSS\_n](https://www.ruby-forum.com/u/Juan_LupiSSS_n)\
**Post date:** [April 29, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/restful-mass-deletion/136179/2 "2008-04-29T17:54:25Z")

</div>

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.

> **[\#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#74 Complex Forms Part 2 - RailsCasts](http://railscasts.com/episodes/74-complex-forms-part-2)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75-complex-forms-part-3)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

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

---

<div class="post-metadata">

**Author:** ![Juan\_LupiSSS\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@Juan\_LupiSSS\_n](https://www.ruby-forum.com/u/Juan_LupiSSS_n)\
**Post date:** [April 29, 2008, 6:51pm UTC](https://www.ruby-forum.com/t/restful-mass-deletion/136179/3 "2008-04-29T18:51:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Juan\_LupiSSS\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@Juan\_LupiSSS\_n](https://www.ruby-forum.com/u/Juan_LupiSSS_n)\
**Post date:** [April 30, 2008, 2:39am UTC](https://www.ruby-forum.com/t/restful-mass-deletion/136179/4 "2008-04-30T02:39:27Z")

</div>

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?”
