# Strategy For Pagination?

**URL:** <https://www.ruby-forum.com/t/strategy-for-pagination/90940>\
**Category:** Rails\
**Created:** [April 3, 2007, 5:58am UTC](https://www.ruby-forum.com/t/strategy-for-pagination/90940 "2007-04-03T05:58:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaurav\_v\_bagga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3d9bf3/32.png) [@gaurav\_v\_bagga](https://www.ruby-forum.com/u/gaurav_v_bagga)\
**Post date:** [April 3, 2007, 5:58am UTC](https://www.ruby-forum.com/t/strategy-for-pagination/90940/1 "2007-04-03T05:58:16Z")

</div>

Hi all,

I have a situation where I have to display results in the form of  
page. To go about implementing I though of two things.

1. I keep the query as per the selection made by user in session and  
limit the result every time user asks for a different page.This means  
every time hitting the Db.

2)I get the complete result in a session variable eg: array of model  
instances and then use index of arrays to paginate the result.This  
will involve lot of memory usage.

I’ll appreciate if someone guides me how to go about this.Displaying  
result in pages is not an issue but the the way to achieve it has put  
me on the back foot.

Regards  
Gaurav V Bagga

---

<div class="post-metadata">

**Author:** ![gaurav\_v\_bagga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3d9bf3/32.png) [@gaurav\_v\_bagga](https://www.ruby-forum.com/u/gaurav_v_bagga)\
**Post date:** [April 3, 2007, 9:35am UTC](https://www.ruby-forum.com/t/strategy-for-pagination/90940/2 "2007-04-03T09:35:39Z")

</div>

Gaurav,

I may be misunderstanding you, but here is my take on it.

In nearly all typical pagination scenarios, #1 will be the way to go.

Trying to manually do it in memory is probably going explode your  
application server as the volume of records grows along with the number  
of users.

From my experience you have to ask yourself how much is enough before  
determining a strategy for pagination.

If your user needs to page through a few hundred records, in batches of  
10-50, then you should not have any issue using either the built in  
paginator, or better yet the most excellent paginator built by Bruce  
Williams ([http://codefluency.com/projects](http://codefluency.com/projects)).

From a useability standpoint, I still live by the words of a developer  
who shared the following advice - if you expect your users to page  
through thousands or tens of thousands of records, you don’t know your  
users or use your own software.

You may want to consider other ways for users to locate what they are  
looking for. Tags, dates, categories, search capabilties all allow you  
to change the presentation of the data and allow users to find the  
desired data more quickly than paging through page after page of  
records.

Anyway, hope this helps.

–  
Lon
