In the database, I store 0 if gender is female and 1 if gender is male.
I have a form field like this:
<%= myobject.select(:gender, options_for_select([['Male', 1], ['Female', 0]]), {:prompt => 'Select Gender'})%>
Which works well when:
- The field doesn't exist in the object it has selected the 'Select Gender' (no value) option.
- The field is male in the database it has selected the Male option
However, if the field is Female it shows the Select Gender option. I believe is because the 0 in the database is thought as false when is retrieved (because Rails assumes 0 in Mysql is false) and therefore in the select it thinks it has to prompt the non value text.
How should I deal with this situation assuming I can't touch the database structure.
tinyintto meanbooleanfor MySQL, that's where the 1 and 0 mangling comes from. Can you change your schema? - mu is too short