• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

I made a new pagination library for the NamedScope era.
You can use will_paginate for ordinary case.
It must be better than the young PaginationScope library.
But if you want to paginate with complicated chained named_scopes, this is suitable.

Usage

At first, include the module into your model class.

rails>>
class Post
include PaginationScope
<<--

By this, the scope named "paginate" is made.

And then, in the controller of which you want to use pagination,
you can get the scope for pagination like this.

rails>>
class PostsController < ApplicationController
def index
@posts = Post.not_deleted.paginate(params[:page], 10)
<<--

Finally, the pagination links are generated by calling the view helper, like this.

html>>
<%= paginate @posts %>
<<--

Have fun!

posted by takiuchi takiuchi on Sat 16 Aug 2008 at 23:57 with 0 comments