Problem with Pagination

Hi Guys,

I am trying to paginate the results from a search. When I use actual
constants in the search conditions, it works fine:

def query
@k2_result_pages, @k2_results = paginate (:k2_results,
:conditions => [‘e_date >= ? AND
e_date <= ?’, ‘2006-07-12’, ‘2006-08-12’],
:per_page => 5,
:order_by => ‘e_date,name’)
end

However, if I change it to use the POST parameters in the conditions
instead, the pagination fails. It correctly shows that I have 14
records and also shows that there are 3 pages, but when I click on “next
page”, it gives me an error saying that I have a nil when I didn’t
expect it.

def query
@k2_result_pages, @k2_results = paginate (:k2_results,
:conditions => [‘e_date >= ? AND
e_date <= ?’, params[:res][:start], params[:res][:stop]],
:per_page => 5,
:order_by => ‘e_date,name’)
end

Any ideas what I can do or look for?
Cheers
Mohit.

Mohit S. wrote:

Hi Guys,

I am trying to paginate the results from a search. When I use actual
constants in the search conditions, it works fine:

def query
@k2_result_pages, @k2_results = paginate (:k2_results,
:conditions => [‘e_date >= ? AND
e_date <= ?’, ‘2006-07-12’, ‘2006-08-12’],
:per_page => 5,
:order_by => ‘e_date,name’)
end

However, if I change it to use the POST parameters in the conditions
instead, the pagination fails. It correctly shows that I have 14
records and also shows that there are 3 pages, but when I click on “next
page”, it gives me an error saying that I have a nil when I didn’t
expect it.

def query
@k2_result_pages, @k2_results = paginate (:k2_results,
:conditions => [‘e_date >= ? AND
e_date <= ?’, params[:res][:start], params[:res][:stop]],
:per_page => 5,
:order_by => ‘e_date,name’)
end

Any ideas what I can do or look for?
Cheers
Mohit.

Can you post your request to Server please. I am just trying to see what
params are coming in.

ajaya

Hi Mohit,

I bet you are not sending the start and stop params on the subsequent
page requests. For example, I have some pages that need to send a
:query param with each request using this:

<%= pagination_links @gift_pages, :params => {:query => @query} %>

Also, another thing I like to do when I have this sort of thing happen
is just print out the params using params.inspect to see what is
happening.

Tom

On 8/7/06, Mohit S. [email protected] wrote:

                                    :order_by => 'e_date,name')
                                    :conditions => ['e_date >= ? AND

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Tom D.

http://atomgiant.com
http://gifthat.com

Double check that params[:res] is not nil. 9 times out of 10, that’s
what gets me.

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

Tom D. wrote:

happening.

Tom
Hi Duane, Tom and Ajaya,

Thanks for your replies.

You are right - I had been trying for quite a while to figure out how to
send the parameters to the next page when using POST. However, I have
now migrated the form so that it uses GET and have used your code above

  • and it works fine!

Cheers
Mohit.