# Will\_paginate problem

**URL:** <https://www.ruby-forum.com/t/will-paginate-problem/162639>\
**Category:** Rails\
**Created:** [March 12, 2009, 10:31am UTC](https://www.ruby-forum.com/t/will-paginate-problem/162639 "2009-03-12T10:31:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![engamocap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e99b99/32.png) [@engamocap](https://www.ruby-forum.com/u/engamocap)\
**Post date:** [March 12, 2009, 10:31am UTC](https://www.ruby-forum.com/t/will-paginate-problem/162639/1 "2009-03-12T10:31:06Z")

</div>

I searched in Internet ([http://wiki.github.com/mislav/will\_paginate/](http://wiki.github.com/mislav/will_paginate/)  
simple-search and [#51 will\_paginate - RailsCasts](http://railscasts.com/episodes/51)), but I can’t  
solve my problem about pagination. The first page is ok, but when I  
click the “Next page” or any other page link, I lose the FIELD1,  
FIELD2, FIELD3 parameter(s). Can you help me? Thank you very much.

class Model \< ActiveRecord::Base

…

def self.display(cond, par, page)  
paginate :all,  
:include =\> [:table1, :table2],  
:conditions =\> [cond, par].flatten,  
:page =\> page,  
:per\_page =\> 10  
end

## end

class ModelController \< ApplicationController

def start  
…  
end  
…

def view  
condition = “1=1”  
param = []  
(condition+=" AND models.FIELD1=?“; param \<\< params  
[:FIELD1].values) if params[:FIELD1]  
(condition+=” AND models.FIELD2=?“; param \<\< params  
[:FIELD2].values) if params[:FIELD2]  
(condition+=” AND models.FIELD3=?"; param \<\< params  
[:FIELD3].values) if params[:FIELD3]  
@items = Model.display(condition, param, params[:page])  
end

## end

view.html.erb

## … \<%= will\_paginate @items %\>

start.html.erb  
…  
\<% form\_tag(:action =\> “view”, :method =\> “get”) do %\>  
… # define FIELD1, FIELD2 and FIELD3  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![engamocap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e99b99/32.png) [@engamocap](https://www.ruby-forum.com/u/engamocap)\
**Post date:** [March 12, 2009, 10:53am UTC](https://www.ruby-forum.com/t/will-paginate-problem/162639/2 "2009-03-12T10:53:31Z")

</div>

Whether FIELD1, FIELD2,FIELD3 are table column heading or values?

---

<div class="post-metadata">

**Author:** ![engamocap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e99b99/32.png) [@engamocap](https://www.ruby-forum.com/u/engamocap)\
**Post date:** [March 12, 2009, 11:35am UTC](https://www.ruby-forum.com/t/will-paginate-problem/162639/3 "2009-03-12T11:35:02Z")

</div>

FIELD1, FIELD2 and FIELD3 are table columns and values. They have the  
same names.

On Mar 12, 10:53 am, Priya B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![engamocap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e99b99/32.png) [@engamocap](https://www.ruby-forum.com/u/engamocap)\
**Post date:** [March 12, 2009, 1:38pm UTC](https://www.ruby-forum.com/t/will-paginate-problem/162639/4 "2009-03-12T13:38:18Z")

</div>

I think you are not getting my question… I asked whether FIELD1,  
FIELD2,FIELD3 are table column headings? Like

Eg:

S.No Name RollNo Address  
1 xx xxx xxxx

S.No Name RollNo Address are column heading. Need to show this in all  
pages?

---

<div class="post-metadata">

**Author:** ![engamocap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e99b99/32.png) [@engamocap](https://www.ruby-forum.com/u/engamocap)\
**Post date:** [March 12, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/will-paginate-problem/162639/5 "2009-03-12T17:39:50Z")

</div>

On Mar 12, 2009, at 4:54 AM, engamocap wrote:

> def self.display(cond, par, page)
> 
> ## (condition+=" AND models.FIELD2=?"; param \<\< params … \<%= will\_paginate @items %\>
> 
> start.html.erb  
> …  
> \<% form\_tag(:action =\> “view”, :method =\> “get”) do %\>  
> … # define FIELD1, FIELD2 and FIELD3  
> \<% end %\>

\<%= will\_paginate @items, :params =\> params %\>

or a suitable subset of the items from params

:params =\> params.reject {|k,v| k !~ /FIELD/ }

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
