Pagination + Search Parameters. How?

Hi!

I’m having trouble to pass filter parameters on my search form while
using paginator, the issue is that when I click in the “Next Page”
link, the current params are not passed along.

I’m using this in my view:

<%= text_field ‘search’, ‘name’ %>

and this for the links:

<%= pagination_links(@users_pages, :params => params[:search]) %>

This way the URL will have the parameters, but won’t be under :search
anymore and in the controller I expect something like this:
params[:search][:name].

I’ve searched for older posts but still can’t get it working. So, I
wonder if someone can help me to figure out what’s the best way to get
this working.

Thanks!

Hey Felipe,

First off, I don’t think :params => “” is a viable link_to attribute and
second, im not sure you can put an array into the pagination method.

It depends on how you identify the text-field in the controller, but you
may want to try:

<%= text_field ‘search’, ‘name’ %>

<%= pagination_links(@users_pages, :searchname =>
params[:search][:name]) %>

Then you can call params[:searchname] in your controller to get whatever
was typed in the search name text_field.

Good Luck,

  • Eric

Felipe,

I’m having trouble to pass filter parameters on my search form
while
using paginator, the issue is that when I click in the “Next Page”
link, the current params are not passed along.

Should you decide to write the pagination links yourself, it’s pretty
easy to just change the page number in the url (and keep the other -
search - parameters) :

in application_helper.rb:

def link_to_page(i)
link_to i, params.merge({:page =>i})
end

More generally, url_for can often be called with only the parameter(s)
you can to change, because the missing values will be filled from the
current request parameters.
Ex:
url_for(:language => ‘sw’)

see:
ActionController::Base

Alain

blog.ravet.com