# Simple problem of negating boolean in params-hash

**URL:** <https://www.ruby-forum.com/t/simple-problem-of-negating-boolean-in-params-hash/169290>\
**Category:** Rails\
**Created:** [June 2, 2009, 12:05am UTC](https://www.ruby-forum.com/t/simple-problem-of-negating-boolean-in-params-hash/169290 "2009-06-02T00:05:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@Adrian\_D](https://www.ruby-forum.com/u/Adrian_D)\
**Post date:** [June 2, 2009, 12:05am UTC](https://www.ruby-forum.com/t/simple-problem-of-negating-boolean-in-params-hash/169290/1 "2009-06-02T00:05:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Adrian\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@Adrian\_D](https://www.ruby-forum.com/u/Adrian_D)\
**Post date:** [June 2, 2009, 12:08am UTC](https://www.ruby-forum.com/t/simple-problem-of-negating-boolean-in-params-hash/169290/2 "2009-06-02T00:08:19Z")

</div>

On Jun 1, 6:49 pm, Adrian D [removed\_email\_address@domain.invalid](mailto: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
