# Multiple deletions using check boxes

**URL:** <https://www.ruby-forum.com/t/multiple-deletions-using-check-boxes/117677>\
**Category:** Rails\
**Created:** [October 19, 2007, 9:18am UTC](https://www.ruby-forum.com/t/multiple-deletions-using-check-boxes/117677 "2007-10-19T09:18:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruchita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ruchita](https://www.ruby-forum.com/u/ruchita)\
**Post date:** [October 19, 2007, 9:18am UTC](https://www.ruby-forum.com/t/multiple-deletions-using-check-boxes/117677/1 "2007-10-19T09:18:09Z")

</div>

Hi,

I am trying to delete multiple products by using check boxes… but not  
able to do it. Can anyone tell me how to use checkboxes to delete  
multiple products on clicking of a button.

Any help would be greatly appreciated.

Regards,  
Ruchita S…

---

<div class="post-metadata">

**Author:** ![ruchita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ruchita](https://www.ruby-forum.com/u/ruchita)\
**Post date:** [October 19, 2007, 9:58am UTC](https://www.ruby-forum.com/t/multiple-deletions-using-check-boxes/117677/2 "2007-10-19T09:58:15Z")

</div>

Ruchita S. wrote:

> Regards,  
> Ruchita S…

Hi, what have you tried so far?

Cheers,  
Mohit.  
10/19/2007 | 3:56 PM.

---

<div class="post-metadata">

**Author:** ![ruchita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ruchita](https://www.ruby-forum.com/u/ruchita)\
**Post date:** [October 19, 2007, 10:08am UTC](https://www.ruby-forum.com/t/multiple-deletions-using-check-boxes/117677/3 "2007-10-19T10:08:29Z")

</div>

Mohit S. wrote:

> Ruchita S. wrote:
> 
> > Regards,  
> > Ruchita S…
> 
> Hi, what have you tried so far?
> 
> Cheers,  
> Mohit.  
> 10/19/2007 | 3:56 PM.

yeah I am putting my code here, I am not able to delete the product list  
from the database:

view:

 \<% i = 0 @products.each do |product| i = i + 1 %\> \<% end %\> 

| Selection | Name |
| --- | --- |
| \<%= check\_box('id\_'+i.to\_s, 'checked', {}, product.title, '') %\> | \<%= product.title %\> |

  

controller:  
def deleteSelection  
@products = Product.find :all

```
    i = 0
  products = @products.clone
  products.each { |product|
    i = i + 1
  if (params['id_'+i.to_s] != nil) then
    checked = params['id_'+i.to_s]['checked']
    if (checked != nil && checked.length > 0) then
       if (product.title == checked) then
         render_text "ccc"
      # render_text product.title
        @products.delete(product)
        i = i-1
        end
    end
  end
}
 render_action 'list'

```

end

---

<div class="post-metadata">

**Author:** ![ruchita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ruchita](https://www.ruby-forum.com/u/ruchita)\
**Post date:** [October 19, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/multiple-deletions-using-check-boxes/117677/4 "2007-10-19T20:19:44Z")

</div>

On 10/19/07, Ruchita S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I am trying to delete multiple products by using check boxes… but not  
> able to do it. Can anyone tell me how to use checkboxes to delete  
> multiple products on clicking of a button.
> 
> Any help would be greatly appreciated.

The latest RailsCasts might be useful:

> **[\#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.

They are a series, showing how to do CRUD on multiple models from a  
single view. The last one covers editing and deletion, but you  
probably want to watch all three.

He’s using links instead of checkboxes, but the same principles should  
apply.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![ruchita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ruchita](https://www.ruby-forum.com/u/ruchita)\
**Post date:** [October 20, 2007, 6:15am UTC](https://www.ruby-forum.com/t/multiple-deletions-using-check-boxes/117677/5 "2007-10-20T06:15:31Z")

</div>

Rick Denatale wrote:

> On 10/19/07, Ruchita S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi,
> > 
> > I am trying to delete multiple products by using check boxes… but not  
> > able to do it. Can anyone tell me how to use checkboxes to delete  
> > multiple products on clicking of a button.
> > 
> > Any help would be greatly appreciated.
> 
> The latest RailsCasts might be useful:
> 
> [#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73)  
> [#74 Complex Forms Part 2 - RailsCasts](http://railscasts.com/episodes/74)  
> [#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75)
> 
> They are a series, showing how to do CRUD on multiple models from a  
> single view. The last one covers editing and deletion, but you  
> probably want to watch all three.
> 
> He’s using links instead of checkboxes, but the same principles should  
> apply.
> 
> –  
> Rick DeNatale
> 
> My blog on Ruby  
> [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

Hi,

Thanks a lot. These tutorials are really very helpful.

-Ruchita
