# Radio\_button() problem with collections

**URL:** <https://www.ruby-forum.com/t/radio-button-problem-with-collections/142304>\
**Category:** Rails\
**Created:** [July 6, 2008, 3:48pm UTC](https://www.ruby-forum.com/t/radio-button-problem-with-collections/142304 "2008-07-06T15:48:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveluscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@steveluscher](https://www.ruby-forum.com/u/steveluscher)\
**Post date:** [July 6, 2008, 3:48pm UTC](https://www.ruby-forum.com/t/radio-button-problem-with-collections/142304/1 "2008-07-06T15:48:41Z")

</div>

Hi -  
I think I’m seeing a bug in rails but am not sure. Maybe I’m just  
struggling. Could somebody take a look at this?

I have a form to enter runner’s times for an ultra marathon. The form  
has 20 rows so we can enter 20 runners times at one submit. Each row has  
the fields bibNumber, dayIn, timeIn, dayOut, and timeOut where we record  
the times that a runner enters and departs a check point. I am using  
radio buttons for the user to select the dayIn and dayOut fields and the  
available choices are “Fri”, “Sat”, or “Sun”, as it’s a 48 hour race  
spanning Friday 6am through Sunday 6am.

In my generated html, I can’t get both the id attribute and the name  
attribute to be indexed at the same time. I get either one but not both  
depending on how I use the radio\_button() helper.

If I use the following code in my partial, I see the subsequent html:

code:  
\<%= radio\_button(:runner\_time, :dayIn, “Fri”, {:index =\>  
runner\_time\_counter}) %\>  
  
\<%= radio\_button(:runner\_time, :dayIn, “Sat”, {:index =\>  
runner\_time\_counter}) %\>  
  
  
\<%= radio\_button(:runner\_time, :dayIn, “Sun”, {:index =\>  
runner\_time\_counter}) %\>

html:

Notice the id isn’t indexed, so on a form with 20 rows of this, my  
 tags can’t reference unique radio buttons, they all end  
up referencing the top one.

I have noticed if I use the following code, the id is indexed (or  
unique), but the name isn’t so my data isn’t submitted correctly:

code:  
\<%= radio\_button(:runner\_time, :dayIn, :value =\> “Fri”, :index =\>  
runner\_time\_counter) %\>  
  
  
\<%= radio\_button(:runner\_time, :dayIn, :value =\> “Sat”, :index =\>  
runner\_time\_counter) %\>  
  
  
\<%= radio\_button(:runner\_time, :dayIn, :value =\> “Sun”, :index =\>  
runner\_time\_counter) %\>

html:

Does anybody know how I get the id and name to be indexed so this page  
will work?

Thank you!  
Steve

---

<div class="post-metadata">

**Author:** ![steveluscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@steveluscher](https://www.ruby-forum.com/u/steveluscher)\
**Post date:** [July 7, 2008, 3:35am UTC](https://www.ruby-forum.com/t/radio-button-problem-with-collections/142304/2 "2008-07-07T03:35:24Z")

</div>

So nobody’s replied. I also did a search on radio\_button and read the  
posts that came up. There are about 3 other posts on this same subject  
and NONE of them have replies. I think there’s a bug here. If I get  
time I’ll look into the rails source and make a patch that works for me.  
I don’t know how to determine if it will function correctly for all  
rails use cases, so I’ll just post it here and let people use it if they  
want.

For now I’m under a tight deadline and I’ll try to use radio\_button\_tag  
and hand code the parameters, maybe that’ll work.

---

<div class="post-metadata">

**Author:** ![steveluscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@steveluscher](https://www.ruby-forum.com/u/steveluscher)\
**Post date:** [July 7, 2008, 5:06am UTC](https://www.ruby-forum.com/t/radio-button-problem-with-collections/142304/3 "2008-07-07T05:06:45Z")

</div>

Here’s my solution using radio\_button\_tag. Several things appear to  
work:  
It submits the dayIn and dayOut in a way that seems it will work  
The tags work.  
The only unknown will be if I can preset the values from the action  
class before showing the page.

---

<div class="post-metadata">

**Author:** ![steveluscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@steveluscher](https://www.ruby-forum.com/u/steveluscher)\
**Post date:** [July 7, 2008, 5:07am UTC](https://www.ruby-forum.com/t/radio-button-problem-with-collections/142304/4 "2008-07-07T05:07:36Z")

</div>

Just kidding. Here’s the real solution:

\<%= radio\_button\_tag(“runner\_time[” + runner\_time\_counter.to\_s +  
“][dayIn]”, “Fri”) %\>  
Fri  
  
  
\<%= radio\_button\_tag(“runner\_time[” + runner\_time\_counter.to\_s +  
“][dayIn]”, “Sat”) %\>  
Sat  
  
  
\<%= radio\_button\_tag(“runner\_time[” + runner\_time\_counter.to\_s +  
“][dayIn]”, “Sun”) %\>  
Sun
