[Rails] Re: Typecasting and boolean attributes

Derek Haynes
Thu, 12 Jan 2006 05:02:49 -0000

But that''s the problem...if I set the value of the radio button to
"1", it won''t show up as selected when rendering the view
because
Rails will only mark it selected if its value is "true."

So if I set the value as 1, the attribute value is saved correctly to
the DB...but then the button won''t be selected as the attribute it is
tied to has a value of "true."

As you said:
true == 1.

- Derek

- Derek

On 1/11/06, Kevin Olbrich <kevin.olbrich@duke.edu>
wrote:
> Derek Haynes wrote:
> > when updating, it does not appear that the params[:group][:public]
> > value is being typecast correctly.
> >
> > As params[:group][:public] = "true", "true" should
be resolved to a
> > "1" in the database. However, this is not occurring.
>
> What is typecasting?
>
> Seriously, radio buttons return string literals back in the params, so
> true comes back as "true".  If you want it to map to 1 or 0, set
the
> radio button to return "1" or "0".
>
> in ruby at least....
>
> true.to_s => "true"
>
> (true == 1) => false
>
> _Kevin
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails