开发者

Rails will_paginate and paging newest records in ASC order

开发者 https://www.devze.com 2023-01-27 18:21 出处:网络
How to paginate posts with w开发者_开发技巧ill_paginate, so that first page shows 10 latest posts 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

精彩评论

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