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.
Double check that params[:res] is not nil. 9 times out of 10, that''s what gets me. Duane Johnson (canadaduane) http://blog.inquirylabs.com/ On Aug 7, 2006, at 1:36 PM, Mohit Sindhwani 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. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
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 Sindhwani <mo_mail@onghu.com> 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. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tom Davies http://atomgiant.com http://gifthat.com
Mohit Sindhwani 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 -- Posted via http://www.ruby-forum.com/.
Tom Davies wrote:> 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. > > TomHi 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.