# Radio\_button in a loop not working

**URL:** <https://www.ruby-forum.com/t/radio-button-in-a-loop-not-working/56853>\
**Category:** Rails\
**Created:** [April 4, 2006, 11:51pm UTC](https://www.ruby-forum.com/t/radio-button-in-a-loop-not-working/56853 "2006-04-04T23:51:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aznowicz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cc9497/32.png) [@aznowicz](https://www.ruby-forum.com/u/aznowicz)\
**Post date:** [April 4, 2006, 11:51pm UTC](https://www.ruby-forum.com/t/radio-button-in-a-loop-not-working/56853/1 "2006-04-04T23:51:41Z")

</div>

```
Hi!

```

I’m a RoR newbie and i’m trying to make this sample code work…

I must be able to choose whether or not to switch lights on/off (one  
light per line)

\<% @valeurs.each do |@v| %\> 

```
   <td><%= radio_button('v[]', 'etat', "Off") %> Off</td>
   <td><%= radio_button('v[]', 'etat', "On") %> On</td>

   <td>Intensite :<%= text_field('v[]', 'intensite') %></td>
</tr>

```

\<% end %\>

| Light \<%= Light.find(@v.light\_id).nom %\>: |

I understand the problem : because I use v[] as name in each  
radio\_button, I can select only one radio\_button whatever the line.

But I don’t know how to address this. Kind of newbie problem I think,  
some help appreciated 😉

In my controller:  
(If no value found, I generate some values with defaults code so that  
the table displays correctly:)

* * *

@scenario = Scenario.find(params[:id])  
@valeurs=Valeur.find\_all\_by\_scenario\_id(params[:id], :order =\> “light\_id  
ASC”)

if (@valeurs == nil) | (@valeurs.length == 0)  
lights=Light.find\_all  
lights.each do |l|  
@valeur = Valeur.new do |v|  
v.light\_id = l.id  
v.scenario\_id = params[:id]  
v.intensite = 0  
v.etat = “Off”  
end  
@valeurs.push(@valeur)  
end  
end

* * *

Thanks again…
