I am trying to get information on which radio button is selected in the same ERB file that it is selected in.
I have an array that will always have 3 items in it. I run through that array and add them as radio buttons in the following code:
<% my_array.each do |item| %>
<input type="radio" id="<%=item%>" name="selected_item" value="<%=item%>">
<label for="<%=item%>"><%=item%></label>
<% end %>
Then a few lines lower I am trying to access the selected item with the following code:
<%= "TEST: #{selected_item}" %>
But it always bombs out with the following error message:
2016-05-04 23:51:24 - NameError - undefined local variable or method `selected_item'>
Any help on why it can't seem to find the radio button would be really helpful.
Aucun commentaire:
Enregistrer un commentaire