This question already has an answer here:
- only select one checkbox 7 answers
I have a form in my rails app with checkboxes that I actually want to behave like a select with a list. I want my user to be only able to select one checkbox at a time (so if he clicks the other checkbox the originally selected checkbox is automatically unchecked). Here's my code :
<%= f.fields_for :answer do |a| %>
<%= a.label "Answer Type :" %>
<br>
<% Answer.answer_type.options.each do |option| %>
<%= a.label option.first %>
<%= a.check_box(:answer_type, { multiple: false}, option.first, nil) %>
<br>
<% end -%>
<% end -%>
Is there a nice rails way to achieve that ?
Aucun commentaire:
Enregistrer un commentaire