# Checkboxes in a loop - I get the same id

**URL:** <https://www.ruby-forum.com/t/checkboxes-in-a-loop-i-get-the-same-id/187210>\
**Category:** Rails\
**Created:** [April 19, 2010, 10:20pm UTC](https://www.ruby-forum.com/t/checkboxes-in-a-loop-i-get-the-same-id/187210 "2010-04-19T22:20:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![oreng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8e8cbc/32.png) [@oreng](https://www.ruby-forum.com/u/oreng)\
**Post date:** [April 19, 2010, 10:20pm UTC](https://www.ruby-forum.com/t/checkboxes-in-a-loop-i-get-the-same-id/187210/1 "2010-04-19T22:20:55Z")

</div>

\<% f.fields\_for :keys do |key\_form| %\>  
\<%= check\_box\_tag “keys\_to\_update[]”, key\_form.object.id %\>  
\<%= key\_form.label :name, key\_form.object.name %\>  
\<% end %\>

This is the output:

I try to use cucumber and check only one of them (or all of them) but  
need an id.

Thanks!

---

<div class="post-metadata">

**Author:** ![oreng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8e8cbc/32.png) [@oreng](https://www.ruby-forum.com/u/oreng)\
**Post date:** [April 19, 2010, 11:07pm UTC](https://www.ruby-forum.com/t/checkboxes-in-a-loop-i-get-the-same-id/187210/2 "2010-04-19T23:07:46Z")

</div>

what about key\_form.id?

---

<div class="post-metadata">

**Author:** ![oreng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8e8cbc/32.png) [@oreng](https://www.ruby-forum.com/u/oreng)\
**Post date:** [April 20, 2010, 12:35am UTC](https://www.ruby-forum.com/t/checkboxes-in-a-loop-i-get-the-same-id/187210/3 "2010-04-20T00:35:34Z")

</div>

On Apr 19, 9:19 pm, oren [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This is the output:
> 
> I try to use cucumber and check only one of them (or all of them) but  
> need an id.

You can override the automatically generated id with anything of your  
choice (the last argument to check\_box\_tag is a hash of html options

Fred

---

<div class="post-metadata">

**Author:** ![oreng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8e8cbc/32.png) [@oreng](https://www.ruby-forum.com/u/oreng)\
**Post date:** [April 22, 2010, 11:41pm UTC](https://www.ruby-forum.com/t/checkboxes-in-a-loop-i-get-the-same-id/187210/4 "2010-04-22T23:41:47Z")

</div>

works, thank you!

On Apr 19, 10:32 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
