views:

124

answers:

2

This is really racking my brain, but maybe I'm trying to hard.

I'm passing a param via a URL (example.com?debug=true)

So I basically want to say:

if params[:debug] == true
 do xyz
else
 do abc
end

But for whatever reason that if statement just isn't doing like it seems like it should.

Is there a better way to do that if/else statement based on a param being true or false?

The debug param will either have a value of true, no value, or a value of false (as far as the URL goes).

+12  A: 

params come in as strings, so you need to compare against "true", not true.

sepp2k
That was the problem...wasn't comparing as a string.
Shpigford
+1  A: 

But for whatever reason that if statement just isn't doing like it seems like it should.

I can almost guarantee that it is doing exactly what it should. When things don't make sense, one of our assumptions is wrong.

Is the value actually a boolean or is it string (or something else?). If the value is a string then of course the comparison to the boolean value true will fail. Try comparing to 'true' and see if that works.

Ed Swangren