# Searching with pagination

**URL:** <https://www.ruby-forum.com/t/searching-with-pagination/148531>\
**Category:** Rails\
**Created:** [September 14, 2008, 12:25pm UTC](https://www.ruby-forum.com/t/searching-with-pagination/148531 "2008-09-14T12:25:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 14, 2008, 12:25pm UTC](https://www.ruby-forum.com/t/searching-with-pagination/148531/1 "2008-09-14T12:25:33Z")

</div>

I’ve got a search action that submits to itself and allows users to  
search through a list of people by firstname and/or lastname.

On submitting the form the action detects POST method, performs the  
search and renders a results template.

My question is how can I integrate pagination with the search results?

If I use pagination like normal it will revert to GET method and thus  
display the search form again.

What is the accepted procedure for doing this?

Thanks

Matt

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 14, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/searching-with-pagination/148531/2 "2008-09-14T13:47:00Z")

</div>

Erol F. wrote:

> > If I use pagination like normal it will revert to GET method and thus  
> > display the search form again.
> > 
> > What is the accepted procedure for doing this?
> > 
> > Thanks
> > 
> > Matt
> 
> What pagination method or plugin are you using?

I’m currently using will\_paginate, which works beautifully for the main  
contact list.

I’m just not sure how to get it integrate with a POST search.

Thanks

Matt

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 14, 2008, 1:41pm UTC](https://www.ruby-forum.com/t/searching-with-pagination/148531/3 "2008-09-14T13:41:43Z")

</div>

On Sep 14, 6:23 pm, Matt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> What is the accepted procedure for doing this?
> 
> Thanks
> 
> Matt

What pagination method or plugin are you using?

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 14, 2008, 2:43pm UTC](https://www.ruby-forum.com/t/searching-with-pagination/148531/4 "2008-09-14T14:43:51Z")

</div>

Erol F. wrote:

> Correct me if I’m wrong, but you want the pagination link to be  
> rendered as POST methods, right? Have you tried creating your own  
> custom link render?

I haven’t tried doing it myself yet, I just thought there would be a  
problem as each click of a standard page link would be a GET request and  
that would cause the action to display the form instead of the results.

I think I have an idea how to get round it so I’ll post again if I’m  
still in trouble 🙂

Thanks

Matt

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 14, 2008, 2:46pm UTC](https://www.ruby-forum.com/t/searching-with-pagination/148531/5 "2008-09-14T14:46:46Z")

</div>

On Sep 14, 8:32 pm, Matt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > Matt  
> > > still in trouble 🙂
> 
> Thanks
> 
> Matt

Give the custom link renderer a try first and render your pagination  
links with link\_to :method =\> :post.

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 14, 2008, 2:11pm UTC](https://www.ruby-forum.com/t/searching-with-pagination/148531/6 "2008-09-14T14:11:37Z")

</div>

On Sep 14, 7:46 pm, Matt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m currently using will\_paginate, which works beautifully for the main  
> contact list.
> 
> I’m just not sure how to get it integrate with a POST search.
> 
> Thanks
> 
> Matt

Correct me if I’m wrong, but you want the pagination link to be  
rendered as POST methods, right? Have you tried creating your own  
custom link render?

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 14, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/searching-with-pagination/148531/7 "2008-09-14T18:20:41Z")

</div>

Hi Matt

On Sep 14, 11:23 am, Matt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’ve got a search action that submits to itself and allows users to  
> search through a list of people by firstname and/or lastname.
> 
> On submitting the form the action detects POST method, performs the  
> search and renders a results template.
> 
> My question is how can I integrate pagination with the search results?

Why don’t you use :method =\> :get on your form instead which will put  
your search criteria into the query string and then the subsequent get  
requests from the will\_paginate links will just append the page to the  
querystring and all work fine. From a REST point of view the search  
action would use the GET verb anyway as it is retrieving a list.

Graham
