I'm sorry for posting another question about this same piece of code but I'm such a newbie to rails it's painful. My question is, I'd like to get a third radio button to be selected when the default value in the DB is present. In other words, i have three buttons "true", "false", and "either". If nothing is selected yet or if the user has selected the "either" button, i'd like that selection to be displayed. Currently if the user chooses "true" or "false", then that selection is reflected properly and as expected. It's just that third option being selected that's not being reflected when the form is saved or brought up again. Here's my code:
<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, " ", { :checked => (:served_in_us_army.nil? or :served_in_us_army.blank? ? true : false) } %>
<%= label :served_in_us_army, 'Either', {:style => 'display:inline'} %>
<%= f.error_message_on :served_in_us_army %>
</div>
EDIT: I should note that also tried the ":checked" option without the curly braces. Still no luck.
Not sure if this is the best solution, but here is how i've solved the issue (i needed the field value not the column name):
<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, " ", :checked => matching_profile.served_in_us_army.nil? %>
<%= label :served_in_us_army, "Either", {:style => 'display:inline'} %>
<%= f.error_message_on :served_in_us_army %>
</div>