Hello- I''m trying to use a select list for a boolean field in my model. I want there to be three values in the list: nil, true, and false. Here are the snippets of code I have so far: <%= f.select :yes_to_terms, [[''Yes'', true], [''No'', false]], :include_blank => ''--select one-- %> The problem I''m running into is that if someone selects ''--select one--'' in the drop-down and submits the form, my app interprets the ''-- select one--'' as false (it''s values is an empty string in the html). I tried changing the list of options to this: [[''--select one--'', nil], [''Yes'', true], [''No'', false]] But that didn''t work either. Does anyone have any ideas? Also, I can''t use a checkbox for this app, since I need to know whether the value is true, false, or unknown. Regards, Eric --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eric Marthinsen wrote:> Hello- > > I''m trying to use a select list for a boolean field in my model. I > want there to be three values in the list: nil, true, and false. Here > are the snippets of code I have so far: > > <%= f.select :yes_to_terms, [[''Yes'', true], [''No'', > false]], :include_blank => ''--select one-- %> > > The problem I''m running into is that if someone selects ''--select > one--'' in the drop-down and submits the form, my app interprets the ''-- > select one--'' as false (it''s values is an empty string in the html). > > I tried changing the list of options to this: > > [[''--select one--'', nil], [''Yes'', true], [''No'', false]] > > But that didn''t work either. Does anyone have any ideas? Also, I can''t > use a checkbox for this app, since I need to know whether the value is > true, false, or unknown. > > Regards, > EricHi Try this one [[''--select one--'', ''''], [''Yes'', true], [''No'', false]] might be you will get value nil when user select ''select one'' Thanks Brijesh Shah -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the reply, but that doesn''t work either. It recognizes the blank string as false. On Jan 2, 2:13 am, Brijesh Shah <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Eric Marthinsen wrote: > > Hello- > > > I''m trying to use a select list for a boolean field in my model. I > > want there to be three values in the list: nil, true, and false. Here > > are the snippets of code I have so far: > > > <%= f.select :yes_to_terms, [[''Yes'', true], [''No'', > > false]], :include_blank => ''--select one-- %> > > > The problem I''m running into is that if someone selects ''--select > > one--'' in the drop-down and submits the form, my app interprets the ''-- > > select one--'' as false (it''s values is an empty string in the html). > > > I tried changing the list of options to this: > > > [[''--select one--'', nil], [''Yes'', true], [''No'', false]] > > > But that didn''t work either. Does anyone have any ideas? Also, I can''t > > use a checkbox for this app, since I need to know whether the value is > > true, false, or unknown. > > > Regards, > > Eric > > Hi > Try this one > [[''--select one--'', ''''], [''Yes'', true], [''No'', false]] > might be you will get value nil when user select ''select one'' > Thanks > Brijesh Shah > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
if you want three values, then boolean true false cant work. I have
done this using 0 and 1 as below:
= select_tag :drop_ship,
options_for_select([['''',''''],[''Drop
Ship'',''1''],
[''Not Drop Ship'',''0'']], params[:drop_ship])
You dont say how you want to use the tri-value in your code, but I use
this directly into a named_scope
has_finder :delisted, lambda {|*args|
args.first.blank? ? {:conditions=>nil} : {:conditions=>
[''obsolete = ? '', args.first]}
which works fine because i am using mysql with boolean of 0=false,
1=true.
If you are checking the params value in the controller then you will
be looking to detect, blank?, ''0'' or ''1''
Tonypm
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---