How to insert a null value into DB using radio_button and form_for formhelper

advertisements

I don't want to argue about wether or not a null value can be considered a boolean - I know it can't. I still, however, want to insert a null value into the (postgres) DB. The column is of type boolean. How can I accomplish this with a radio button? Here is what I've tried:

<div class="new-partner-form">
<%= form_for [:admin, matching_profile.partner, matching_profile],  :html => {:id => "edit_profile", :multipart => true} do |f| %>
  <div class="rounded-block semi-wide clear">
    <h4>Military Service</h4>
    <%= f.radio_button :served_in_us_army, false %>
    <%= label :served_in_us_army, 'NO', {:style => 'display:inline'} %>
    <%= f.radio_button :served_in_us_army, true %>
    <%= label :served_in_us_army, 'YES', {:style => 'display:inline'} %>
    <%= f.radio_button :served_in_us_army, nil %>
    <%= label :served_in_us_army, 'NO PREFERENCE', {:style => 'display:inline'} %>
    <%= f.error_message_on :served_in_us_army %>
  </div>


What about just setting a default value for the column of null? In your form, instead of using the f.radio_button, just use plain old html and set the name so that it isn't picked up with the structure of what you are submitting for your create action.