Simple problem of negating boolean in params-hash


#1

Hi,

I have a simple problem. I get a boolean value in the parameter hash
and want to negate it. But somehow I missed there a fundamental
concept, because that doesn’t make any sense to me:

Code:

test1 = !params[:editmode]
test2 = params[:editmode]

logger.info(“Editmode: #{params[:editmode]} Test 1: #{test1} und Test
2: #{test2}”)

Output:

“Editmode: false Test 1: false und Test 2: false”

or when editmode is true: “Editmode: true Test 1: false und Test 2:
true”

Thanks for your help


#2

On Jun 1, 6:49 pm, Adrian D removed_email_address@domain.invalid wrote:

Hi,

I have a simple problem. I get a boolean value in the parameter hash
and want to negate it. But somehow I missed there a fundamental
concept, because that doesn’t make any sense to me:

Code:

test1 = !params[:editmode]
test2 = params[:editmode]

All controller parameters are strings, so this negation doesn’t do
what you think it does (because strings are not nil and they are not
the boolean value false, any string always has the logical value true,
and its negation the logical value false). You need to compare the
parameters with whatever string you have decided represents true/false

Fred