Ramy Abdel-Azim
2011-Nov-23 02:28 UTC
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?
<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 Filter'', {:style
=>
''display:inline''} %>
<%= f.error_message_on :served_in_us_army %>
</div>
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Nov-23 07:55 UTC
Re: How to insert a null value into DB using a radio_button with form_for
On Nov 23, 2:28 am, Ramy Abdel-Azim <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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> <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 Filter'', {:style => > ''display:inline''} %> > <%= f.error_message_on :served_in_us_army %> > </div> > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.