开发者

How do you use Kaminari to paginate a page by a number value?

开发者 https://www.devze.com 2023-03-29 13:03 出处:网络
I\'开发者_运维知识库ve set up Kaminari so that it can accurately paginate by post title if i do this:

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')
0

精彩评论

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