开发者

Rails will_paginate and paging newest records in ASC order

How to paginate posts with w开发者_开发技巧ill_paginate, so that first page shows 10 latest posts in ASC order.

Thanks!


If I understood correctly, this code should do the job in your controller.


def index
 @posts = Post.paginate :page => params[:page], :per_page => 10, :order => 'created_at ASC'
end


Try adding this to your post model right at the top:

cattr_reader :per_page
@@per_page = 10
default_scope :order => 'created_at DESC'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜