# Controller if statement error with param

**URL:** <https://www.ruby-forum.com/t/controller-if-statement-error-with-param/157141>\
**Category:** Rails\
**Created:** [January 7, 2009, 7:08pm UTC](https://www.ruby-forum.com/t/controller-if-statement-error-with-param/157141 "2009-01-07T19:08:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fididle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fididle](https://www.ruby-forum.com/u/fididle)\
**Post date:** [January 7, 2009, 7:08pm UTC](https://www.ruby-forum.com/t/controller-if-statement-error-with-param/157141/1 "2009-01-07T19:08:26Z")

</div>

Hi, Please help me with this maddening little problem.

The if statement in the controller (below) does not detect the string  
“ALL” contained in params[:state]. This param was entered in a form  
(not shown here).

I can see on the rendered page (below) that this variable is indeed  
present in the ‘@state’ variable as it is rendered correctly.

The question then is why the if ‘@state == “ALL”’ condition is not  
“true”? If it were true, @debug should be == 1.

I have also tried using a regex ‘if @state =~ /ALL/’ to no avail.

Thanks!

* * *

## controller

…  
def search  
…  
@state = params[:state]  
@debug = 0  
if @state == “ALL”  
@debug = 1  
end  
…  
end

* * *

## view

…

DEBUG: @state = \<%= @state %\>  
 DEBUG: @debug = \<%= @debug %\>

...
* * *

## rendered page

DEBUG: @state = ALL  
DEBUG: @debug = 0

Thanks!

---

<div class="post-metadata">

**Author:** ![fididle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fididle](https://www.ruby-forum.com/u/fididle)\
**Post date:** [January 7, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/controller-if-statement-error-with-param/157141/2 "2009-01-07T20:25:01Z")

</div>

Hi,

are you sure its a string? just check with @state.class, and also try to  
print the value before the if (so as to confirm its not getting modified  
later on)

-NAYAK

On Wed, Jan 7, 2009 at 11:38 PM, Fididle Fididle \<

---

<div class="post-metadata">

**Author:** ![fididle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fididle](https://www.ruby-forum.com/u/fididle)\
**Post date:** [January 8, 2009, 12:26am UTC](https://www.ruby-forum.com/t/controller-if-statement-error-with-param/157141/3 "2009-01-08T00:26:00Z")

</div>

Vishwanath Nayak wrote:

> Hi,
> 
> are you sure its a string? just check with @state.class, and also try to  
> print the value before the if (so as to confirm its not getting modified  
> later on)
> 
> -NAYAK
> 
> On Wed, Jan 7, 2009 at 11:38 PM, Fididle Fididle \<

Thanks Nayak. I was trying to compare an array with a simple string.  
Changing the test (below) works.

* * *

## controller

…  
def search  
…  
@state = params[:state]  
@debug = 0  
if @state[0] == “ALL”  
@debug = 1  
end  
…  
end
