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'
精彩评论