Forum: Ruby on Rails radio_button in a loop not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E2aec8d639b67319450c1f1b25a7a60b?d=identicon&s=25 Fx Aznowicz (aznowicz)
on 2006-04-04 23:51
    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)

<table>
<% @valeurs.each do |@v| %>
	<tr>
	   <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>
	</tr>
<% end %>
</table>

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...
This topic is locked and can not be replied to.