[Rails] params object nil in controller action

linux user fanoflinux at gmail.com
Wed Aug 9 13:35:11 GMT 2006


On 8/8/06, Trevor Squires <trevor at protocool.com> wrote:
>
> Hey,
> just scanning your code, there's a red flag.... see below:
>
> On 8-Aug-06, at 11:35 AM, linux user wrote:
>
> 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]
>
>
>
> hmmm.... what are you doing in the line above?  seems to me your
> obliterating params with the value of session[:incidentSearch]
>
> Regards,
> Trevor
> --
> Trevor Squires
> http://somethinglearned.com
>

You are right Trevor it is obliterating params with value of
session[:incidentSearch] and thats what I want to do, because
somewhere below this code
when the session[:incidentSearch] is nil I am storing the params in
session[:incidentSearch]. So next time around I want to use the params
stored
in the session[:incidentSearch] when the user clicks on a link called
"Back to Search Results".

The question is that for the very first time when the
session[:incidentSearch] is nil, the code

  params = session[:incidentSearch]

should never be executed. so there is no chance the params should be
nil. But immideately right outside the if-end block my params are nil,
even the line which obliterates params never got executed.

So why is params nil.

-daya

    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
>
>
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060809/f79c57fb/attachment.html


More information about the Rails mailing list