I have this page that renders a table of data that I’d like to display
in multiple pages. I’m trying to use pagination_by_sql and
pagination_links, but I have a problem figuring out how to re-recreate
the url generated by a select helper form in order for the pagination
links’ parameters to be in the right format.
To elaborate, I have data that is generated by form select helpers
like the following:
<%= select(:filter_key, :received_at, @select_dates ) %>
and
<%= select(:filter_key, :user, @select_users ) %>
So, when submitted, the url will look like this:
/list?filter_key%5Breceived_at%5D=2006-10-17&filter_key%5Buser%5D=ADMIN&commit=Filter
And subsequently, the params hash becomes:
params =>
{“commit”=>“Filter”,“action”=>“list”,“filter_key”=>{“user”=>“ADMIN”,“received_at”=>“2006-10-17”},
“controller”=>“audit_records”}
Notice how filter_key is a hash containing the keys “user” and
“received_at”. In my controller, I set
@filter_keys = params[:filter_key]
so that I could parse the data to create my sql query. This makes
@filter_keys to be
@filter_keys=>{“user”=>“ADMIN”,“received_at”=>“2006-10-17”}
Now, in the resulting page, I used pagination_links to give me the
following:
<%= pagination_links(@audit_record_pages,:params => {“filter_key” =>
{@filter_keys}}) %>
If I hover over the link to page 2, I see what’s going to be passed
through the url:
list?filter_keys=userADMINreceived_at2006-10-17&page=2
which is different from the original url. And so, my code breaks
when trying to parse out
filter_keys=userADMINreceived_at2006
Seeing how pagination_links flattens out the hash in a manner
different from when using form selects, are there any suggestions on
how I can get around this?
Thanks in advance,
-Al