3

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?

Jon
  • 129
  • 1
  • 9

2 Answers2

1

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?

Akira Matsuda
  • 1,854
  • 14
  • 9
  • ah, it's sorted correctly now. for some reason, the pageview values were not saving. – Jon Aug 22 '11 at 14:50
1

May be you need desc at order clause? because currently it will order 0 views first.

 Post.order('pageviews desc')
YOU
  • 120,166
  • 34
  • 186
  • 219