Pagination Question


#1

Hi -

I’ve just started working with Rails, having come from a Cold Fusion
background. I’m curious how best to deal with a huge result set. For
example, I’m building an app that contains users. I’ve used
scaffolding to setup my initial pages for CRUD operations on users.
All that is great. The problem is, I’m going to end up with 1000+
users in this app once it’s done. Having people paginate through 1000
users to find the one they want seems a bit tedious. Is there a nice
Rails way to handle this problem? Like some way to filter down the
result list by last name, or user group, etc. i.e. take some input
from the user and use that to make the pagination list smaller? Any
help is appreciated. Thanks!

Josh


#2

You can add :conditions to the pagination which have query strings
attached
based on a search query. So for example, you could add a case

if params[:lastname]
conditions = ['lastname like ‘%:lastname%’, {:lastname =>
params[:lastname]}]
end

paginate :users, :per_page => 50, :order => ‘lastname’, :conditions =>
conditions

Check out
http://railsmanual.org/module/ActionController%3A%3APagination/paginate
for
more information.

  • Nb
 Nathaniel S. H. Brown                           http://nshb.net

#3

Josh Black wrote:

result list by last name, or user group, etc. i.e. take some input
from the user and use that to make the pagination list smaller? Any
help is appreciated. Thanks!

One word: autocomplete. Use an AJAX autocompleter to narrow the list in
near-ish real-time, with a drop-box to select the relevant one. Much
simpler than parameterised search pages, and more intuitive for the
user, too.


#4

This sounds awesome. Is there any documentation or examples for
something like this that I could look at? Thanks again for all the
help.


#5

On Jan 3, 2006, at 5:08 AM, Alex Y. wrote:

One word: autocomplete. Use an AJAX autocompleter to narrow the
list in near-ish real-time, with a drop-box to select the relevant
one. Much simpler than parameterised search pages, and more
intuitive for the user, too.

Apologies for changing the subject line, but I’m trying to use
autocomplete and it’s not working.

Relevant line from my view:
<%= text_field_with_auto_complete (‘dealing’, ‘which_store’,
{}, :skip_style=>true) %>

relevant lines from my controller:

def auto_complete_for_dealing_which_store
search = params[:dealing][:which_store]
@stores = Dealing.search(search) unless search.blank?
render :partial => ‘live_search’
end

and my entire partial:

    <% for deal in @dealings.to_a %>
  • <%= link deal.which_store, deal %>
  • <% end %>

Any idea? Please CC responses to me or they will get lost in the rest
of the emails. Thanks!

Cheers,
Hasan D. removed_email_address@domain.invalid


#6

Hasan D. wrote:

and my entire partial:

    <% for deal in @dealings.to_a %>
  • <%= link deal.which_store, deal %>

What’s the ‘link’ method? Do you mean ‘link_to’?