public
Description: Simple and flexible pagination using named scopes and partials.
Homepage:
Clone URL: git://github.com/cjbottaro/paginate_izzle.git
cjbottaro (author)
Tue Jul 15 19:53:37 -0700 2008
commit  d5c644604b2e903cb8cfff864c426556920a1ccb
tree    73362485b8407b5fddee20f618d31c9c533d0e68
parent  fb23a30533efd75cd3c4444e0f5ece61c93bd1f1
README.rdoc

Simple and flexible pagination using named scopes and partials.

I didn’t like how will_paginate tried to infer the counting sql from the main query. Specifically, if I wanted to do eager loading, then the counting sql did unnecessary joins. I like keeping the counting sql separate from the query because it gives the user more control. It’s also more explicit and easier to understand what’s going. This entire plugin is extremely simple and easy to understand, thus easy to modify if you so choose.

Example

  # model code
  class Post < ActiveRecord::Base
    pagination :per_page => 10
    has_many :subscribers
  end

  # action code
  def some_action
    @posts = Post.active.latest.paginate(params[:page]).all(:include => :subscribers) # eager loading requires a join
    post_count = Post.active.latest.count # no unnecessary join
    @paginator = Post.paginator(params[:page], post_count)
  end

  # view code
  <%= render_paginator(@paginator) %>

More

This plugin is pretty flexible. You can specify a bunch of rendering options and/or write your own partial to render the widget. See the documentation for Paginator::DEFAULT_OPTIONS, Paginator#pages and _default_paginator.html.erb.

More examples to come on how to use the rendering options and how to create your own rendering partial.

Copyright © 2008 Christopher J. Bottaro <cjbottaro@alumni.cs.utexas.edu>, released under the MIT license