David,

I experienced this exact same problem. I echo your sentiments and you
are very correct that it is a bug and a big pain. Thanks for posting
the problem and a working solution:

Here is my *now* working snippet of code:

<%= f.select :male, [["Male", true],["Female", false]],
{:include_blank=>true, :selected=>@user.male.to_s} %>

Thanks again,
Sean

On Nov 23 2010, 12:19 pm, David Cross <[email protected]> wrote:
> And.. yes.. I am replying to myself a lot, but I found a workaround
> that indicates that this IS a bug, it has *NEVER* worked.  People just
> got lucky because of the default order of choices.
>
> To make this work it is as "easy" as:
> [f.]select([object], :method, [["Yes", true],["No", false]]
> {:include_blank=>true, :selected=>@object.method.to_s})
>
> @object.method.to_s  is the "magic" there.  for whatever idiotic,
> stupid, time-wasting reason, "false" and "nil" are NEVER matching
> anything.  In fact if you remove the ":include_blank" there, and keep
> that ordering, *false* will show up as "Yes"/true... because
> 'selected' doesn't get set, since it doesn't match anything in the
> list.
>
> This is *horribly* broken behavior, and a patch should be made.
> Someone flips an option somewhere and they could wind up trashing
> countless data before they realize "false"/nil doesn't actually match
> anything.
>
> --
> David E. Cross
>
> On Nov 23, 12:24 pm, David Cross <[email protected]> wrote:
>
>
>
>
>
>
>
> > Ok.. I have been doing some experimentation.. and honestly, now I am
> > beginning to get a bit ticked off with how inconsistently this is being
> > handled....
>
> > For example, if you replace the f.select() in my example code with:
>
> > select_tag("working", options_for_select([["", ""], ["Yes", true],
> > ["No",false]], @testing.working))
>
> > it WORKS!  (well minus the posting values back to the form and having it
> > update the database since its not in the model..
>
> > HOWEVER:
> > f.select (:working, [["", ""], ["Yes", true], ["No", false]], {:selected =>
> > @testing.working})
>
> > does NOT work.
>
> > REALLY?!
>
> > In fact I changed the selections choices to have ["first", "first"] ahead of
> > the "" choice to test a theory that it wasn't actually matching
> > _anything_... and it turns out that's what its doing, for the case of
> > "false" it doesn't actually match ANYTHING.  you can replace ":selected =>
> > false" and it won't work, it will select "Yes".. go ahead, try it.)...
> > HOWEVER, it works just fine with select_tag?!  AUUUGH.
>
> > I've been through the rails code a couple of times, but I cannot see where
> > this obtuse bug is laying.
>
> > --
> > David E. Cross
>
> > On Mon, Nov 22, 2010 at 3:25 PM, David Cross <[email protected]> wrote:
> > > Sorry, I took a break for the weekend, here it is in .tgz format:
>
> > >http://www.cs.rpi.edu/~crossd/selecttest.tgz<http://www.cs.rpi.edu/%7Ecrossd/selecttest.tgz>
>
> > > --
> > > David E. Cross
>
> > > On Nov 20, 11:30 am, pepe <[email protected]> wrote:
> > > > Hi David,
>
> > > > Can you post your application in a different format? I need a C
> > > > compiler to install bzip2 and I'd rather not go into all that.
>
> > > > Thanks.
>
> > > --
> > > 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 [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected]<rubyonrails-talk%2Bunsubscrib
> > >  [email protected]>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/rubyonrails-talk?hl=en.

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to