浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Will Paginate

Pagination is just limiting the number of records displayed. Why should you let it get in your way while developing, then? This plugin makes magic happen. Did you ever want to be able to do just this on a model:

  Post.paginate :page => 1, :order => 'created_at DESC'

… and then render the page links with a single view helper? Well, now you can.

Some resources to get you started:

Example usage

Use a paginate finder in the controller:

    @posts = Post.paginate_by_board_id @board.id, :page => params[:page], :order => 'updated_at DESC'

Yeah, paginate works just like find — it just doesn’t fetch all the records. Don’t forget to tell it which page you want, or it will complain! Read more on WillPaginate::Finder::ClassMethods.

Render the posts in your view like you would normally do. When you need to render pagination, just stick this in:

    <%= will_paginate @posts %>

You’re done. 

 

http://www.tricksonrails.com/2010/04/rails3-and-will_paginate-doing-easy-remote-links-rails3-tricks-02/

posted on 2010-11-07 11:11  lexus  阅读(385)  评论(0编辑  收藏  举报