• 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.

   1  class Post
   2    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.

   1  class PostsController < ApplicationController
   2    def index
   3      @posts = Post.not_deleted.paginate(params[:page], 10)

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

   1  <%= paginate @posts %>

Have fun!

posted by Png takiuchi on Sat 16 Aug 2008 at 23:58

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry788
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ