I’m working on a Rails application where I have some a set of two radio buttons where users can click “yes” or “no”. The MySQL DB column created by the ActiveRecord migration is a tinyint.
If the user doesn’t click either radio button I want MySQL to store NULL. (The column allows NULL.) And when they come back to edit the data, neither button should be checked.
What’s happening is that ActiveRecord is storing 0 and then when I come back the “No” button is checked.
Rails 2.3.5
Form code (I’m using Haml):
= f.radio_button( :model_attribute, true )
Yes
= f.radio_button( :model_attribute, false )
No
(In retrospect it probably would have been better to use a single checkbox, but it would be difficult to change that now.)
This seems to defeat the idea of radio buttons (i.e., choose one out of a set). If it is important to track “no response”, then would it be possible to add a third radio button for this option? If you don’t want the user selecting a response and then re-selecting “no response”, you can selectively choose to display the button on your form based on its current value.