# Pagination Question

**URL:** <https://www.ruby-forum.com/t/pagination-question/56057>\
**Category:** Rails\
**Created:** [January 3, 2006, 7:16am UTC](https://www.ruby-forum.com/t/pagination-question/56057 "2006-01-03T07:16:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@Josh\_Black](https://www.ruby-forum.com/u/Josh_Black)\
**Post date:** [January 3, 2006, 7:16am UTC](https://www.ruby-forum.com/t/pagination-question/56057/1 "2006-01-03T07:16:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Josh\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@Josh\_Black](https://www.ruby-forum.com/u/Josh_Black)\
**Post date:** [January 3, 2006, 10:36am UTC](https://www.ruby-forum.com/t/pagination-question/56057/2 "2006-01-03T10:36:49Z")

</div>

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](http://railsmanual.org/module/ActionController%3A%3APagination/paginate)  
for  
more information.

- Nb

```auto
 Nathaniel S. H. Brown http://nshb.net

```

---

<div class="post-metadata">

**Author:** ![Josh\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@Josh\_Black](https://www.ruby-forum.com/u/Josh_Black)\
**Post date:** [January 3, 2006, 2:06pm UTC](https://www.ruby-forum.com/t/pagination-question/56057/3 "2006-01-03T14:06:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Josh\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@Josh\_Black](https://www.ruby-forum.com/u/Josh_Black)\
**Post date:** [January 3, 2006, 7:00pm UTC](https://www.ruby-forum.com/t/pagination-question/56057/4 "2006-01-03T19:00:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Josh\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@Josh\_Black](https://www.ruby-forum.com/u/Josh_Black)\
**Post date:** [January 3, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/pagination-question/56057/5 "2006-01-03T20:30:23Z")

</div>

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](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Josh\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@Josh\_Black](https://www.ruby-forum.com/u/Josh_Black)\
**Post date:** [January 4, 2006, 12:06pm UTC](https://www.ruby-forum.com/t/pagination-question/56057/6 "2006-01-04T12:06:44Z")

</div>

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’?
