I have a select list for a boolean column in postgresql in the ''model'' ... YES_NO = [ [ "Yes", "1" ], [ "No", "0" ] ].freeze in the ''view code'' ... <%= options = [[''Accepted?'', '''']] + Placement::YES_NO select("placement", "accepted", options) %> When creating new records, I can select Yes or No and it writes the proper value to table. When I edit existing records, unlike other select list menus which automatically go to the existing value in the select list, the ''Accepted'' list always displays "Accepted?'' (the prompt, never the value) in the pop-up selected list, no doubt because it cannot figure out the reverse translation of existing column 0''s and 1''s backwards to Yes : No logic. What is the trick to do that? Thanks Craig
Kevin Olbrich
2006-Mar-01 07:35 UTC
[Rails] another select_list question - bad bad booleans
I know this doesn''t answer your question... it''s late here, but why are you using a drop down for a binary choice instead of something like a check box or radio button? _Kevin On Tuesday, February 28, 2006, at 11:36 PM, Craig White wrote:>I have a select list for a boolean column in postgresql > >in the ''model'' ... > YES_NO = [ > [ "Yes", "1" ], > [ "No", "0" ] > ].freeze > >in the ''view code'' ... > ><%= options = [[''Accepted?'', '''']] + Placement::YES_NO > select("placement", "accepted", options) %> > >When creating new records, I can select Yes or No and it writes the >proper value to table. > >When I edit existing records, unlike other select list menus which >automatically go to the existing value in the select list, the >''Accepted'' list always displays "Accepted?'' (the prompt, never the >value) in the pop-up selected list, no doubt because it cannot figure >out the reverse translation of existing column 0''s and 1''s backwards to >Yes : No logic. > >What is the trick to do that? > >Thanks > >Craig > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-- Posted with http://DevLists.com. Sign up and save your time!
Probably because I understood drop down boxes (at least until this issue) and hadn''t bothered to do any checkboxes/radio buttons yet. - No reason that I can''t change my bad habits I guess. It does sort of make sense to use a radio button since either is required and I suppose I can default it one way for ''new'' records. Hmm...radio buttons... Probably too late to tackle tonight as I am pretty much fried but even with radio buttons, I will have to reverse the binary logic of stored boolean back to common Yes/No vernacular. Thanks Craig On Wed, 2006-03-01 at 07:35 +0000, Kevin Olbrich wrote:> I know this doesn''t answer your question... it''s late here, but why are > you using a drop down for a binary choice instead of something like a > check box or radio button? > > _Kevin > > On Tuesday, February 28, 2006, at 11:36 PM, Craig White wrote: > >I have a select list for a boolean column in postgresql > > > >in the ''model'' ... > > YES_NO = [ > > [ "Yes", "1" ], > > [ "No", "0" ] > > ].freeze > > > >in the ''view code'' ... > > > ><%= options = [[''Accepted?'', '''']] + Placement::YES_NO > > select("placement", "accepted", options) %> > > > >When creating new records, I can select Yes or No and it writes the > >proper value to table. > > > >When I edit existing records, unlike other select list menus which > >automatically go to the existing value in the select list, the > >''Accepted'' list always displays "Accepted?'' (the prompt, never the > >value) in the pop-up selected list, no doubt because it cannot figure > >out the reverse translation of existing column 0''s and 1''s backwards to > >Yes : No logic. > > > >What is the trick to do that? > > > >Thanks > > > >Craig > > > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >
using radio buttons for a boolean defies logic as I can''t make sense of the api radio_button_tag(name, value, checked = false, options = {}) from my example below... <%= radio_button_tag(''placement'', ''accepted'' ''?'' %> field is to have either 0 or 1 - display should be "Yes" or "No" The pop-up list for Yes or No works fine except that in edit mode, the value already exists in the column and all I really need is for it to preselect "Yes" or "No" based upon the column contents. The above radio button api (with absolutely no examples) doesn''t make a lick of sense to me. Craig On Wed, 2006-03-01 at 07:35 +0000, Kevin Olbrich wrote:> I know this doesn''t answer your question... it''s late here, but why are > you using a drop down for a binary choice instead of something like a > check box or radio button? > > _Kevin > > On Tuesday, February 28, 2006, at 11:36 PM, Craig White wrote: > >I have a select list for a boolean column in postgresql > > > >in the ''model'' ... > > YES_NO = [ > > [ "Yes", "1" ], > > [ "No", "0" ] > > ].freeze > > > >in the ''view code'' ... > > > ><%= options = [[''Accepted?'', '''']] + Placement::YES_NO > > select("placement", "accepted", options) %> > > > >When creating new records, I can select Yes or No and it writes the > >proper value to table. > > > >When I edit existing records, unlike other select list menus which > >automatically go to the existing value in the select list, the > >''Accepted'' list always displays "Accepted?'' (the prompt, never the > >value) in the pop-up selected list, no doubt because it cannot figure > >out the reverse translation of existing column 0''s and 1''s backwards to > >Yes : No logic.
Solved - never mind. Good lesson learned and anyone else using booleans in postgres 0 and 1 are not what rails derives from tables...TRUE FALSE is what rails obtains from tables. Craig On Wed, 2006-03-01 at 18:42 -0700, Craig White wrote:> using radio buttons for a boolean defies logic as I can''t make sense of > the api > > radio_button_tag(name, value, checked = false, options = {}) > > from my example below... > > <%= radio_button_tag(''placement'', ''accepted'' ''?'' %> > > field is to have either 0 or 1 - display should be "Yes" or "No" > > The pop-up list for Yes or No works fine except that in edit mode, the > value already exists in the column and all I really need is for it to > preselect "Yes" or "No" based upon the column contents. The above radio > button api (with absolutely no examples) doesn''t make a lick of sense to > me. > > Craig > > On Wed, 2006-03-01 at 07:35 +0000, Kevin Olbrich wrote: > > I know this doesn''t answer your question... it''s late here, but why are > > you using a drop down for a binary choice instead of something like a > > check box or radio button? > > > > _Kevin > > > > On Tuesday, February 28, 2006, at 11:36 PM, Craig White wrote: > > >I have a select list for a boolean column in postgresql > > > > > >in the ''model'' ... > > > YES_NO = [ > > > [ "Yes", "1" ], > > > [ "No", "0" ] > > > ].freeze > > > > > >in the ''view code'' ... > > > > > ><%= options = [[''Accepted?'', '''']] + Placement::YES_NO > > > select("placement", "accepted", options) %> > > > > > >When creating new records, I can select Yes or No and it writes the > > >proper value to table. > > > > > >When I edit existing records, unlike other select list menus which > > >automatically go to the existing value in the select list, the > > >''Accepted'' list always displays "Accepted?'' (the prompt, never the > > >value) in the pop-up selected list, no doubt because it cannot figure > > >out the reverse translation of existing column 0''s and 1''s backwards to > > >Yes : No logic. > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails