I want user to choose one option out of three for one model.
I.e. I have a model Video, that can be rated as positive/negative/unknown
Currently I have three columns with boolean values (pos/neg/unknown).
Is it the best way to handle this situation?
What should the form look like for this?
Currently I have something like
<%= radio_button_tag :positive, @word.positive, false %>
<%= label_tag :positive, 'Positive' %>
<%= radio_button_tag :negative, @word.negative, false %>
<%= label_tag :negative, 'Positive' %>
<%= radio_button_tag :unknown, @word.unknown, false %>
<%= label_tag :unknown, 'Positive' %>
But obviously it allows multiple selections, while I am trying to restrict it to just one..
What to do?
If would go with a string column let's say rating
.
then in your form:
# ...
<%= f.radio_button :rating, 'unknown', checked: true %>
<%= f.radio_button :rating, 'positive' %>
<%= f.radio_button :rating, 'negative' %>
# ...
It only allows one selection
edit The exact same but using radio_button_tag:
<%= radio_button_tag 'rating', 'unknown', true %>
<%= radio_button_tag 'rating', 'positive' %>
<%= radio_button_tag 'rating', 'negative' %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With