Forum: Ruby on Rails Pagination + Search Parameters. How?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Felipe (Guest)
on 2007-05-08 20:56
(Received via mailing list)
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!
Eric A. (Guest)
on 2007-05-10 00:10
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
Alain R. (Guest)
on 2007-05-10 03:30
(Received via mailing list)
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:
   http://api.rubyonrails.org/classes/ActionControlle...


Alain
----
blog.ravet.com
This topic is locked and can not be replied to.