Pagination has many through problems

Hey,

The first option to paginate expects the Symbol object which is the
name of your table, not an ActiveRecord or a list of ActiveRecord
objects.

Cheers,
Yuri

One of the options is having the following method in your ApplicationController

  def paginate_collection(collection, options = {})
    default_options = {:per_page => 10, :page => params[:page]}
    options = default_options.merge(options)

    pages = Paginator.new(self, collection.size, options[:per_page],
options[:page])
    first = pages.current.offset
    last = [first + options[:per_page], collection.size].min
    slice = collection[first...last]
    return [pages, slice]
  end

This method receives the collection as you see, and returns exactly
what paginate returns. The disadvantage of this solution is that you
have to read the _whole_ list of objects into memory. Though, well,
your initial variant does the same :slight_smile:

Cheers.

Hi Keith. I know we emailed on this already, but I thought I'd post
this for others. In your situation, paginating_find works like this:

@friends = current_user.profile.friends.find(:all, :page => { :size =>
10, :current => params[:page] })

... which, of course, gets you 10 friends associated with the current
user (through the profile). Which 10 friends depends on the value of
params[:page]. So, no more loading *all* the friends if you only want
to show 10 of them at a time...