Paginate do a Count(*) request before

Mathieu,

Paginate needs to know how many total records there are when you
create the object so you must either do an SQL COUNT or get all the
records and find the length of the array. If it’s a small data set,
I say find them all once and save yourself the second SQL query. If
it’s a large data set do the COUNT and then only find the records you
want which will save overhead by retrieving a small amount of data
even though it uses two queries.

I’ve put a page on the Rails Wiki which might help you:
http://wiki.rubyonrails.org/rails/pages/HowtoPagination

To Adam, one tip about your solution. Once you have a Paginator
object that the view can see, you can use its methods to get the
number of items while in the view instead of having to set the
variables @total, @first_msg, @last_msg in the controller. (Everyone
has their own style but I like to keep my controller as streamlined
as I can.) Just use something like this in your view:

Listing
<%= @message_pages.current.first_item %> -
<%= @message_pages.current.last_item %> of
<%= pluralize(@ message_pages.item_count, ‘message’) %>

HTH,
Kevin

I’ve put a page on the Rails Wiki which might help you:
http://wiki.rubyonrails.org/rails/pages/HowtoPagination

Gracefull thanks, You make my day.

Ciao’
Mathieu