# Check\_box not being checked

**URL:** <https://www.ruby-forum.com/t/check-box-not-being-checked/123284>\
**Category:** Rails\
**Created:** [December 15, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/check-box-not-being-checked/123284 "2007-12-15T22:29:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcelo\_Ruiz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b782af/32.png) [@Marcelo\_Ruiz](https://www.ruby-forum.com/u/Marcelo_Ruiz)\
**Post date:** [December 15, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/check-box-not-being-checked/123284/1 "2007-12-15T22:29:14Z")

</div>

I’m new to RoR and I’m having a little problem that I can’t solve.

My model is simple. I have Lists and ListItems.

I have a view that loops through all the list items, and I put the  
HTML for the each list item row in a partial called \_list\_item.rhtml.

This is the view, called show.rhtml

\<%= render(:partial =\> "list\_item", :collection =\> @list.list\_items) %\>

And this is the partial \_list\_item.rhtml

- \<%= check\_box 'list\_item', 'done' %\> \<%= list\_item.text %\>

As you can see, my list\_item has two fields: done and text.

The problem is that even though the field done is an integer “1” I  
can’t get the checkbox to get checked!!!

The rest works as expected.

Any idea? Thanks!

---

<div class="post-metadata">

**Author:** ![Marcelo\_Ruiz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b782af/32.png) [@Marcelo\_Ruiz](https://www.ruby-forum.com/u/Marcelo_Ruiz)\
**Post date:** [December 15, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/check-box-not-being-checked/123284/2 "2007-12-15T22:34:30Z")

</div>

BTW, same thing happens if I don’t use a partial.

---

<div class="post-metadata">

**Author:** ![Marcelo\_Ruiz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b782af/32.png) [@Marcelo\_Ruiz](https://www.ruby-forum.com/u/Marcelo_Ruiz)\
**Post date:** [December 15, 2007, 11:07pm UTC](https://www.ruby-forum.com/t/check-box-not-being-checked/123284/3 "2007-12-15T23:07:15Z")

</div>

Try putting this at the top of your partial:

\<% @list\_item = list\_item %\>

The magic form helper methods rely on instance variables to set the  
value. Alternatively, you could do this:

\<%= check\_box\_tag “list\_item[done]”, list\_item.done %\>

Michael B.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Marcelo\_Ruiz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b782af/32.png) [@Marcelo\_Ruiz](https://www.ruby-forum.com/u/Marcelo_Ruiz)\
**Post date:** [December 16, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/check-box-not-being-checked/123284/4 "2007-12-16T17:42:25Z")

</div>

Michael B. wrote:

> Try putting this at the top of your partial:
> 
> \<% @list\_item = list\_item %\>

I was struggling with this myself last night.  
Had done this before but forgot about the instance var.

Thanx
