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
-----
...
<p>DEBUG: @state = <%= @state %><br \>
DEBUG: @debug = <%= @debug %><br \>
</p>
...
--------------
rendered page
--------------
DEBUG: @state = ALL
DEBUG: @debug = 0
Thanks!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 > ----- > > ... > > <p>DEBUG: @state = <%= @state %><br \> > DEBUG: @debug = <%= @debug %><br \> > </p> > ... > > > -------------- > rendered page > -------------- > > DEBUG: @state = ALL > DEBUG: @debug = 0 > > > Thanks! > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---