I am having a problem with the select helper method. When I have a select in code: <%= select "registration", "title", TITLES, :include_blank => true %> Where TITLES is equal to: TITLES = { ''Mr.'' => ''0'', ''Mrs.'' => ''1'', ''Miss.'' => ''100'', ''Ms.'' => ''10'' } If a value of ''100'' is stored in my registration object for the title attribute, and I come to this page the html that is outputed looks like this: <select id="registration_title" name="registration[title]"> <option></option> <option value="100" selected="selected">Miss.</option> <option value="1" selected="selected">Mrs.</option> <option value="10" selected="selected">Ms.</option> <option value="0" selected="selected">Mr.</option> </select> Notice that all of them are selected. I believe this is because line 56 of form_options_helper.rb reads: is_selected = ( (selected.respond_to?(:include?) ? selected.include?(element.last) : element.last == selected) ) A String object has an include method, so all four options respond positively when asked if they are included in selected. Is this a bug? -- John Long http://wiseheartdesign.com ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
Or stuff like this? -- John John wrote:> I am having a problem with the select helper method. When I have a > select in code: > > <%= select "registration", "title", TITLES, :include_blank => true > %> > > Where TITLES is equal to: > > TITLES = { > ''Mr.'' => ''0'', > ''Mrs.'' => ''1'', > ''Miss.'' => ''100'', > ''Ms.'' => ''10'' > } > > If a value of ''100'' is stored in my registration object for the title > attribute, and I come to this page the html that is outputed looks > like this: > > <select id="registration_title" name="registration[title]"> > <option></option> > <option value="100" selected="selected">Miss.</option> > <option value="1" selected="selected">Mrs.</option> > <option value="10" selected="selected">Ms.</option> > <option value="0" selected="selected">Mr.</option> > </select> > > Notice that all of them are selected. > > I believe this is because line 56 of form_options_helper.rb reads: > > is_selected = ( (selected.respond_to?(:include?) ? > selected.include?(element.last) : > element.last == selected) ) > > A String object has an include method, so all four options respond > positively when asked if they are included in selected. > > Is this a bug? > > -- > John Long > http://wiseheartdesign.com > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >