# Mislav-will\_paginate & complicated SQL made up from params

**URL:** <https://www.ruby-forum.com/t/mislav-will-paginate-complicated-sql-made-up-from-params/154055>\
**Category:** Rails\
**Created:** [November 24, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/mislav-will-paginate-complicated-sql-made-up-from-params/154055 "2008-11-24T23:25:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [November 24, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/mislav-will-paginate-complicated-sql-made-up-from-params/154055/1 "2008-11-24T23:25:13Z")

</div>

I have a search form which sends a set of params to a controller. The  
params are unpacked and SQL generated which is then fed into  
(1)  
MyModel.paginate\_by\_sql [sql],:page =\> params[:page], :per\_page =\> 30

Which all works fine and lovely, on the first page…

The links in each of the visible page buttons simply point to  
/controller/search\_action?page=2 or 3 & so on. All the params used to  
create the sql are missing. So when the call comes in for the next page,  
only clean no selection sql is generated and I get the second (or third  
& etc) page of the entire data set, not the sub-set selected by the  
form.

When I do this by  
(2)  
AnOtherModel.find\_with\_ferret params[:search\_for],  
{:page=\>params[:page], :per\_page =\> 30}

then search\_for=something is added to the params list attached to the  
pagination links, so I can page back and forth in a search result set.  
So that works OK.

How do I get the params for my query in (1) to be added to the  
pagination links so I get the params back to redo the query for the next  
page?

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [November 25, 2008, 12:23am UTC](https://www.ruby-forum.com/t/mislav-will-paginate-complicated-sql-made-up-from-params/154055/2 "2008-11-25T00:23:04Z")

</div>

On Nov 24, 10:25 pm, John S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> only clean no selection sql is generated and I get the second (or third  
> So that works OK.
> 
> How do I get the params for my query in (1) to be added to the  
> pagination links so I get the params back to redo the query for the next  
> page?

Well you can always add params, it’s one option that you pass to the  
will\_paginate method. If the request being handled is a get then the  
params that made up that request will be added automatically too.

Fred

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [November 25, 2008, 2:26pm UTC](https://www.ruby-forum.com/t/mislav-will-paginate-complicated-sql-made-up-from-params/154055/3 "2008-11-25T14:26:10Z")

</div>

> Well you can always add params, it’s one option that you pass to the  
> will\_paginate method. If the request being handled is a get then the  
> params that made up that request will be added automatically too.
> 
> Fred

Fred,

Thanks for that. I was doing an unusual search such that a method=‘post’  
was being generated even though the resource path was a get. I was  
feeding an object into the form\_for helper which made it think it had to  
do a post.

The reason for feeding an object into the form\_for helper is that I  
wanted an easy way to select various drop down boxes used in the search,  
so I’d created a temporary object on the fly, packed the parameters from  
the search into that object, and sent it back to the browser. This meant  
that if part of the search was made by selecting a country from a list,  
then when the new page was generated the selection would still be on  
that country.

Anyway I got round it by setting :html=\>{:method=\>‘get’}

Thanks
