# Forms containing checkboxes and collections/object lists

**URL:** <https://www.ruby-forum.com/t/forms-containing-checkboxes-and-collections-object-lists/119884>\
**Category:** Rails\
**Created:** [November 11, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/forms-containing-checkboxes-and-collections-object-lists/119884 "2007-11-11T22:39:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![theogb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bb73d2/32.png) [@theogb](https://www.ruby-forum.com/u/theogb)\
**Post date:** [November 11, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/forms-containing-checkboxes-and-collections-object-lists/119884/1 "2007-11-11T22:39:04Z")

</div>

Hi,

I’m really struggling to understand how to get checkboxes to work on a  
list of objects. Essentially I have this:

- An Issue model which has\_many articles
- An Article model which belongs to issue

So, I am pulling up a list of articles, all that are of type ‘ready’ and  
either have an issue\_id of 0 or article.issue\_id == issue.id

I want to have a check box after each in the table. It will be checked  
if you wish add the article to the current issue and unchecked if you  
wish to set the issue\_id for the article to 0 and not include it.

How in the blue blazes of hell do I do this with action view? The  
‘form\_for’ helper only seems to refer to on object not a collection.

On page 498 of ‘Agile Web D. with Rails’ there’s a section  
about ‘Forms Containing Collections’ which implies you can use a text  
field easily enough and this code works, adding an id into each text  
field’s ID. However, doing the same thing with ‘check\_box\_tag’ fails  
brutally (maybe I don’t understand this tag).

So I tried with ‘check\_box’ but all this does is give me an error like  
this:

undefined method `delete’ for 1:Fixnum

referencing the ‘check\_box’ tag. I don’t have ‘delete’ anywhere in my  
code.

I have tried to look over this:  
[http://wiki.rubyonrails.org/rails/pages/CheckboxHABTM](http://wiki.rubyonrails.org/rails/pages/CheckboxHABTM) but there is  
querying of the database in the rhtml code, which seems wrong and not  
something I’m entirely sure I can easily achieve.

Can someone give me a clear and easy way to do this sort of checkbox  
use? Surely this has got to be one of the most basic uses of a checkbox  
in code yet it seems hard to find something about?

Any help will be appreciated, even if it’s just a ‘DURR!’ and a link to  
a very clear code example.

Thanks muchly,  
Theo

---

<div class="post-metadata">

**Author:** ![theogb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bb73d2/32.png) [@theogb](https://www.ruby-forum.com/u/theogb)\
**Post date:** [November 12, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/forms-containing-checkboxes-and-collections-object-lists/119884/2 "2007-11-12T16:05:16Z")

</div>

Check out this railscast.

> **[\#17 HABTM Checkboxes - RailsCasts](http://railscasts.com/episodes/17-habtm-checkboxes)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

On Nov 11, 4:39 pm, Theo Graham-brown \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![theogb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bb73d2/32.png) [@theogb](https://www.ruby-forum.com/u/theogb)\
**Post date:** [November 12, 2007, 7:46pm UTC](https://www.ruby-forum.com/t/forms-containing-checkboxes-and-collections-object-lists/119884/3 "2007-11-12T19:46:54Z")

</div>

Chris B. wrote:

> Check out this railscast.
> 
> [#17 HABTM Checkboxes - RailsCasts](http://railscasts.com/episodes/17)
> 
> On Nov 11, 4:39 pm, Theo Graham-brown \<rails-mailing-l…@andreas-

The problem is I’m not using HABTM. There will only ever be one article  
in any given Issue, though an issue will have many articles.

THis doesn’t seem to work for my requirements.

---

<div class="post-metadata">

**Author:** ![theogb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bb73d2/32.png) [@theogb](https://www.ruby-forum.com/u/theogb)\
**Post date:** [November 12, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/forms-containing-checkboxes-and-collections-object-lists/119884/4 "2007-11-12T19:58:28Z")

</div>

Chris B. wrote:

> Check out this railscast.
> 
> [#17 HABTM Checkboxes - RailsCasts](http://railscasts.com/episodes/17)
> 
> On Nov 11, 4:39 pm, Theo Graham-brown \<rails-mailing-l…@andreas-

Apologies. I think it will work!

Thanks a lot. The webcast is much easier to follow than the Wiki entry  
on a similar subject.

I maybe be back, though. ☹

Thanks for your patience.
