I am using two radio buttons ('yes', 'no') for one single field (here:
In my model I defined the field as required (validates_presence_of).
In my view, field value gets set based on user input. As default no
radio button is set initially.
- If no selection is made by user, exception is thrown => good/expected
- If user selects 'Yes', field is set to true and everything works fine
- If user selects 'No', field is set to 'false', but
validates_presence_of still generates exception => no good/unexpected
Here are the code snipplets:
:message => "Please select yes or no."
Yes<%= f.radio_button :newsletter, true %>
No<%= f.radio_button :newsletter, false %>
<%= error_message_on(:registration, :newsletter)%>
Any hint / advice is very much appreciated.
Thanks in advance!