# Collecting checked checkboxes from table

**URL:** <https://www.ruby-forum.com/t/collecting-checked-checkboxes-from-table/76058>\
**Category:** Rails\
**Created:** [November 15, 2006, 5:04pm UTC](https://www.ruby-forum.com/t/collecting-checked-checkboxes-from-table/76058 "2006-11-15T17:04:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 15, 2006, 5:04pm UTC](https://www.ruby-forum.com/t/collecting-checked-checkboxes-from-table/76058/1 "2006-11-15T17:04:38Z")

</div>

Hi, I’m new to RoR, so this is a beginners question, I know. (Bought  
Agile 2 in pdf, Recipes and Ruby For Rails, stillstudying) So please  
forgive me this very simpel request.

I have a list with rubrics, each with a checkbox. The user ticks a few  
checkboxes, and presses the submitbutton. I’d like to get those rubrics  
that are checked, and store their id in a db.

I have this for the list

\<% form\_for :rubric, :url =\> {:action =\> :checked} do |form| %\> \<%  
@rubrics.each do |@rubric| %\>  
\<%= @rubric.headdrubric %\> ===\>  
\<%= @rubric.partrubric %\>  
\<%= check\_box\_tag(“rubric[]”, @rubric.id)%\>  
  
  
\<% end %\>  
\<%= submit\_tag “Add”, :class =\> “submit” %\>  
\<% end %\>

But after searching this forum, and my books, I am very unsure on how  
to collect the id’s of the chosen rubrics. I think I stumbled on 10  
snippets, thought each time tthis may be it, tried it, always failed.  
Again this is very basic, I suppose, but I really would appriate any  
help or suggestion. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 15, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/collecting-checked-checkboxes-from-table/76058/2 "2006-11-15T17:14:43Z")

</div>

Rudy wrote:

> \<% form\_for :rubric, :url =\> {:action =\> :checked} do |form| %\> \<%  
> to collect the id’s of the chosen rubrics. I think I stumbled on 10  
> snippets, thought each time tthis may be it, tried it, always failed.  
> Again this is very basic, I suppose, but I really would appriate any  
> help or suggestion. Thanks in advance.

Take a look at the submitted params, they should contain an array  
called ‘rubric’ that will contain all of the checked 'id’s.

to see the params, just add this line to the start of your ‘checked’  
action…

raise ‘test’

\_Kevin

---

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 15, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/collecting-checked-checkboxes-from-table/76058/3 "2006-11-15T18:18:54Z")

</div>

Thanks for your prompt reply.  
All I got was

Parameters: {“commit”=\>“Add”, “rubric”=\>[“on”]}

So it looks as if there is no id past on. Or do I misread this message?  
I must admit that I’m a bit lost now. It just seems such an obvious  
example of an simple programming exercice, but I can’t get around it,  
and I can’t find any example. Any ideas? Thanks for replying.

---

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 15, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/collecting-checked-checkboxes-from-table/76058/4 "2006-11-15T18:41:01Z")

</div>

Right. I am not sure yet how to solve it, but I found the reason why  
there was no id. It is so ridiculous, that I deeply feel ashamed, but I  
have to wright it down, to prevent some of these good folks here  
tostart looking for answer. There was no id, because… it was calling  
the one table I copied from another one with all its data in it - and  
you guess, NO id-field. The moment I had added that, it appeared in the  
search.  
That still leaves me hoping for an elegant, simple Ruby-way of  
collecting the info… but I will sleep a lot better tonight. Thanks  
again.
