Radio_button in a loop not working


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>

<% 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 :wink:

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs