I'开发者_运维知识库ve set up Kaminari so that it can accurately paginate by post title if i do this:
def index
...
@posts = Post.order('title').page(params[:page]).per(5)
...
end
i also have <% paginate %> in the view
but if I try something like this
@posts = Post.order('pageviews').page(params[:page]).per(5)
it stops working. There are no bugs or errors, but it just appears to be sorted arbitrarily. Possibly by date. How come?
Firstly, is it correctly sorted without Kaminari?
I mean, how is Post.order('pageviews')
sorted?
Next, can you check the output SQL? How is it sorted if you run
Post.order('pageviews').page(1).to_sql
result on your DB console?
May be you need desc
at order clause? because currently it will order 0 views first.
Post.order('pageviews desc')
精彩评论