Forum: Ruby on Rails Strategy For Pagination?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cd1de7e6a1ff7903b249edc2a4a35b34?d=identicon&s=25 gaurav v bagga (Guest)
on 2007-04-03 05:58
(Received via mailing list)
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.

Gaurav V Bagga
8c49880a7f274947b01d576c5828a5f6?d=identicon&s=25 Lon Baker (spdemac)
on 2007-04-03 09:35
(Received via mailing list)

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 (

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

Anyway, hope this helps.

This topic is locked and can not be replied to.