How to insert a null value into DB using a radio_button with form_for

Hi,

I’m trying to add a third option for a filter using a radio button. It’s
the old null-value-for-a-boolean story. Basically i’d like to add
another radio button labelled “No Filter” which would insert a null
value into the database when selected. Here is my first attempt. The
third button is showing up, but the null value is not being inserted.
What am I missing?

<%= form_for [:admin, matching_profile.partner, matching_profile], :html => {:id => "edit_profile", :multipart => true} do |f| %>

Military Service

<%= 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 Filter', {:style => 'display:inline'} %> <%= f.error_message_on :served_in_us_army %>

On Nov 23, 2:28am, Ramy Abdel-Azim [email protected] wrote:

Hi,

I’m trying to add a third option for a filter using a radio button. It’s
the old null-value-for-a-boolean story. Basically i’d like to add
another radio button labelled “No Filter” which would insert a null
value into the database when selected. Here is my first attempt. The
third button is showing up, but the null value is not being inserted.
What am I missing?

The parameters a rails app gets from a form are always strings,
because that’s all a form can submit. You’ll need to turn the value
back into a nil server-side.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs