Forum: Ruby on Rails radio_button in a loop not working

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Fx A. (Guest)
on 2006-04-05 01:51

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>Light <%= Light.find(@v.light_id).nom %>:</td>

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

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

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

if (@valeurs == nil) | (@valeurs.length == 0)
        lights.each do |l|
            @valeur = do |v|
              v.light_id =
              v.scenario_id = params[:id]
              v.intensite = 0
              v.etat = "Off"

Thanks again...
This topic is locked and can not be replied to.