# Params object nil in controller action

**URL:** <https://www.ruby-forum.com/t/params-object-nil-in-controller-action/101954>\
**Category:** Rails\
**Created:** [August 8, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/params-object-nil-in-controller-action/101954 "2006-08-08T21:30:32Z")\
**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 8, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/params-object-nil-in-controller-action/101954/1 "2006-08-08T21:30:32Z")

</div>

Hi All

I am trying to implement a Back to Search Results functionality, by  
storing  
the user’s search criteria (params) in session and then reusing those  
params instead of request params when user clicks on “Back to Search  
Results  
link”. here is my code

* * *

def search  
if session[:incidentSearch].nil? or session[:incidentSearch].empty?

# if no search criteria found in session

```
  logger.debug("if params.nil?=#{params.nil?}")
  logger.debug("NOT FOUND :incidentSearch")
  if (params[:routeNum].nil? or params[:routeNum].empty?) and
      (params[:incidentId].nil? or params[:incidentId].empty?) and
      (params[:startDateTime].nil? or params[:startDateTime].empty?) 

```

and

```
      (params[:endDateTime].nil? or params[:endDateTime].empty?)
    flash[:warning] = "Don't try stupid things....Enter some search

```

criteria."  
redirect\_to :back and return  
elsif ((!params[:routeNum].empty? or !params[:incidentId].empty?)  
and  
(!params[:startDateTime].empty? and !params[:endDateTime].empty?) or  
(!params[:routeNum].empty? and !params[:incidentId].empty?))  
flash[:warning] = “Specify only one search criteria Reference#  
or  
Route or Date (Start and End both)”  
redirect\_to :back and return  
end

```
elsif !session[:incidentSearch].nil? and

```

!session[:incidentSearch].empty? # if search criteria found in session  
puts “elsif params.nil?=#{params.nil?}”  
logger.debug(“elsif params.nil?=#{params.nil?}”)  
logger.debug(“session[:incidentSearch] found …”)  
params = session[:incidentSearch]  
end

```
logger.debug("final params.nil?=#{params.nil?}") # *print true*
condition = nil
if params[:routeNum] and !params[:routeNum].empty? # *<=== params is 

```

nil  
by now\*\* \*  
condition = ["(route\_num = ?)", params[:routeNum].strip]  
end  
#proceed with find operation in model and render results

* * *

here is my logger output when I search for the first time

if params.nil?=false  
NOT FOUND :incidentSearch  
final params.nil?=true

* * *

The funny thing is for first search the control never reaches elsif  
which  
means session[:incidentSearch] was nil so where is params being set to  
nil

Please help me understand why is params nil

thanks in advance  
-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:11pm UTC](https://www.ruby-forum.com/t/params-object-nil-in-controller-action/101954/2 "2006-08-15T14:11:59Z")

</div>

On Tue, 2006-08-08 at 13:35 -0500, linux user wrote:

> session[:incidentSearch].empty?  
> search criteria."
> 
> ```
> if params[:routeNum] and !params[:routeNum].empty? # <=== params
> 
> ```
> 
> final params.nil?=true
> 
> * * *
> 
> The funny thing is for first search the control never reaches elsif  
> which means session[:incidentSearch] was nil so where is params being  
> set to nil
> 
> Please help me understand why is params nil
> 
> thanks in advance

* * *

on this error screen…there should be a link to the session variables  
so you can see their values directly by clicking the link.

Craig
