# Strange - params.nil? true in controller

**URL:** <https://www.ruby-forum.com/t/strange-params-nil-true-in-controller/64510>\
**Category:** Rails\
**Created:** [August 9, 2006, 5:58pm UTC](https://www.ruby-forum.com/t/strange-params-nil-true-in-controller/64510 "2006-08-09T17:58:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![linux\_user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@linux\_user](https://www.ruby-forum.com/u/linux_user)\
**Post date:** [August 9, 2006, 5:58pm UTC](https://www.ruby-forum.com/t/strange-params-nil-true-in-controller/64510/1 "2006-08-09T17:58:59Z")

</div>

Hi All  
I am trying to implement a functionality where a user clicks on “Back to  
Search Results” link he is taken to the search result screen. For this I  
am  
storing his search criteria (params object) in session. Here is my code

* * *

_def_ search

logger.debug(“params.nil?=#{params.nil?}”) # this prints  
'params.nil?=_false’  
\<=== params is NOT nil at this point_

_if_ session[_:incidentSearch_].nil? _or_  
session[_:incidentSearch_].empty?

params._each_{|k,v| logger.debug(“key: #{k}, value: #{v}”)} #this  
_prints  
the key value pairs perfectly_

logger.debug(“params=#{params.to\_s}”) # this prints  
‘params.nil?=_false_’ \<===  
_params is NOT nil at this point_

# s=params.dup

# params=s

# logger.debug(“params=#{s.to\_s}”)

_if_ params[_:routeNum_].nil? _or_ params[_:routeNum_].empty? \<===  
_params  
is NOT nil at this point_

flash[_:warning_] = “Don’t try stupid things…Enter some search  
criteria.”

redirect\_to _:back_ _and_ _return_

_elsif !params[:routeNum_].empty? and one more condition

flash[_:warning_] = “Specify only one search criteria Reference# or  
Route or  
Date (Start and End both)”

redirect\_to _:back_ _and_ \*return

- 

\*end  
\*

params._each_{|k,v| logger.debug(“key: #{k}, value: #{v}”)}

_elsif_ !session[_:incidentSearch_].nil? _and_  
!session[_:incidentSearch_].empty?

# _control never reaches here for the first time the search is done_

logger.debug("======\> Somebody was here…") # _\<== control never  
reaches here for the first time the search is done_

params = session[_:incidentSearch_] # \*\<== \*_control never reaches  
here,_ _if  
I comment it every thing works fine i.e. params is never nil_

puts “\*_^&^&^_(^%%^%&^$%$%$&%$&$&^$&^ Somebody was here…” #  
_\<== control  
never reaches here and nothing is printed_

\*end

- logger.debug(“params.nil?=#{params.nil?}”) # this prints  
‘params.nil?=\*  
true\*’ \<=== _params is NIL at this point_.

#proceed with search…

* * *

This is a single user development environment. So only one request comes  
in  
for a search… and the params is nil before I can even proceed with  
search.

Can somebody please help me understand where and why is params being set  
to  
nil???

Oh and if I do the following in my first if

_s=params.dup_  
_params=s_

everything works fine

-daya

---

<div class="post-metadata">

**Author:** ![linux\_user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@linux\_user](https://www.ruby-forum.com/u/linux_user)\
**Post date:** [August 15, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/strange-params-nil-true-in-controller/64510/2 "2006-08-15T14:18:30Z")

</div>

On 8/9/06, linux user [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> _params is NOT nil at this point_  
> flash[_:warning_] = "Don’t try stupid things…Enter some search
> 
> Oh and if I do the following in my first if
> 
> _s=params.dup_  
> _params=s_
> 
> everything works fine
> 
> -daya

This is completely wierd since the _elsif_  
!session[_:incidentSearch_].nil?  
_and_ !session[_:incidentSearch_].empty? is never executed.  
Anybody has any ideas.???

-daya
