# Check\_box\_tag nightmare

**URL:** <https://www.ruby-forum.com/t/check-box-tag-nightmare/139149>\
**Category:** Rails\
**Created:** [May 31, 2008, 2:07pm UTC](https://www.ruby-forum.com/t/check-box-tag-nightmare/139149 "2008-05-31T14:07:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![biqut2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biqut2](https://www.ruby-forum.com/u/biqut2)\
**Post date:** [May 31, 2008, 2:07pm UTC](https://www.ruby-forum.com/t/check-box-tag-nightmare/139149/1 "2008-05-31T14:07:44Z")

</div>

I have been struggling to get some check boxes working but have had  
absolutely no luck. Can someone tell me what I am doing wrong. Any help  
would be greatly appreciated.

Here is the code in my view:

```
<% for size in @sizes %>
    <%= f.check_box('size_list[]', size, @item.sizes.collect {|size|

```

size.id}.include?(size.id)) %\>\<%=h size.name %\>  
  
\<% end %\>

Here is the code in my controller:

```
@brands = Brand.find :all
@sizes = Size.find :all
@categories = Category.find :all
@item = Item.find(params[:id])

```

The error I get is:

Showing items/edit.html.erb where line #15 raised:  
undefined method `check\_box\_tag’ for  
#ActionView::Helpers::FormBuilder:0x7f5ca4ed2e90

---

<div class="post-metadata">

**Author:** ![biqut2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biqut2](https://www.ruby-forum.com/u/biqut2)\
**Post date:** [May 31, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/check-box-tag-nightmare/139149/2 "2008-05-31T14:10:28Z")

</div>

PS: I’ve tried it with check\_box\_tag and check\_box both.

---

<div class="post-metadata">

**Author:** ![biqut2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biqut2](https://www.ruby-forum.com/u/biqut2)\
**Post date:** [May 31, 2008, 2:24pm UTC](https://www.ruby-forum.com/t/check-box-tag-nightmare/139149/3 "2008-05-31T14:24:08Z")

</div>

\<…\>

> Here is the code in my view:
> 
> \<% for size in @sizes %\>  
> \<%= f.check\_box(‘size\_list[]’, size, @item.sizes.collect {|size|  
> size.id}.include?(size.id)) %\>\<%=h size.name %\>  
>   
> \<% end %\>

Is that all code in the view, or do you have form\_for here also?

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![biqut2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biqut2](https://www.ruby-forum.com/u/biqut2)\
**Post date:** [May 31, 2008, 2:34pm UTC](https://www.ruby-forum.com/t/check-box-tag-nightmare/139149/4 "2008-05-31T14:34:27Z")

</div>

Here is the entire view as I have it now. I did manage to get the check  
boxes to show up finally but once you submit the form and come back to  
the view again to check that the information was saved correctly they  
are all messed up. For example I have three sizes in my database (10,11,  
and 12) and the first time you view the form these are the three options  
shown but if you select anyof the and submit the form when you refresh  
the form they all three have the same label (12 in my case). I’m just  
plain confused here.

# Editing item

\<%= error\_messages\_for :item %\>

\<% form\_for @item, :html =\> { :multipart =\> true } do |f| %\>

**Brand**  
 \<%= f.select :brand\_id, @brands.collect {|brand| [brand.name, brand.id]} %\>

**Sizes**  
 \<% for size in @sizes %\> \<%= check\_box\_tag('size\_list[]', size.id, @item.sizes.collect {|size| size.id}.include?(size.id)) %\>\<%=h size.name %\>  
 \<% end %\>

**Category**  
 \<%= f.select :category\_id, @categories.collect {|category| [category.name, category.id]} %\>

**Picture**  
 \<%= f.file\_field :picture %\>

**Price**  
 \<%= f.text\_field :price %\>

**Name**  
 \<%= f.text\_field :name %\>

**Description**  
 \<%= f.text\_area :description %\>

\<%= f.submit "Update" %\>

\<% end %\>
