I have a question form with options, however I can't understand why it allows me to select several radio_button options in the same question, when it should only allow me to select one option, I appreciate if you can help me solve this impasse:
<!-- Question -->
<ol>
<% @survey.questions.each do |question| %>
<li><%= question.title %>
<!-- Answer -->
<ol type="a">
<%= form.fields_for :answers do |answer| %>
<%= answer.hidden_field :question_id, value: question.id %>
<!-- Question Option -->
<li>
<% question.question_options.each do |question_option| %>
<!-- Answer Option -->
<%= answer.fields_for :answer_options do |answer_option| %>
<%= answer_option.radio_button :question_option_id, question_option.id %>
<%= answer_option.label :question_option_id, question_option.title %>
<%# answer_option.hidden_field :answer_id %>
<!-- Sub Question Option -->
<ol type="a">
<% question_option.sub_question_options.each do |sub_question_option| %>
<!-- Sub Question Option -->
<%= answer_option.fields_for :sub_answer_options do |sub_answer_option| %>
<li>
<%= sub_answer_option.check_box :sub_question_option_id, { }, sub_question_option.id, nil %>
<%= sub_answer_option.label :sub_question_option_id, sub_question_option.title %>
</li>
<% end %>
<!-- End Sub Question Option -->
<% end %>
</ol>
<!-- End Sub Question Option -->
<% end %>
<!-- End Answer Option -->
<% end %>
</li>
<!-- End Question Option -->
<% end %>
</ol>
<!-- End Answer -->
</li>
<% end %>
</ol>
<!-- End Question -->
This usually happens when you have two radio buttons with different names:
You could check in the generated html what are the names that rails is assigning to them and make the changes in your radio button so that it works correctly (so at first, I don't see what the problem could be). In the worst case, you might consider manually creating your radio buttons with
radio_button_tag
.