Mislav-will_paginate & complicated SQL made up from params


#1

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?


#2

On Nov 24, 10:25 pm, John S. 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


#3

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