Controller if statement error with param

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!

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 <

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs