Topic: Newbie question (boolean)

I want to pass the parameter FALSE in a post request then ruby seems to understand it as a string which acts as TRUE.

Is there a clean Ruby way of avoiding

@force_boolean=(params[:force]=="true")

(and sorry if the question has been raised thousands of times I could not find the google expression to show it)

Last edited by zulu (2007-05-14 10:52:05)

Re: Newbie question (boolean)

params are always strings, so I don't think so. You *might* be able to use 0 and 1, but I doubt that will be handled any different. You'll have to pick a value and see if it equals that like you are doing.

Railscasts - Free Ruby on Rails Screencasts

Re: Newbie question (boolean)

You could always wrap it with eval, but that's not clean or safe.

As in, don't even try, because wrapping a params with eval is one of the most unsafe things you can do.

What you have is pretty much as clean as you'll get it.

Last edited by Firanide (2007-05-14 11:37:34)