EDIT
In getting my hands on the code, I've found the real problem stems from the use of default_scope
.
The original order()
clause specified in your default scope is still being applied, even when adding your own order()
.
As a side note, this issue was kind of fixed in Rails 4.0, but the behavior was reverted in 4.0.1.
The solution was to apply a reorder()
# model
def self.popular
reorder('votes desc').find_with_reputation(:votes, :all)
end
# controller
def index
@microposts = Micropost.page(params[:page]).popular
end
ORIGINAL ANSWER
It seems that using the paginate
method directly may not work with activerecord-reputation-system
,
However, I found some examples showing that you can use the will_paginate
page
and per
methods:
Perhaps it will work like this:
Micropost.page(params[:page]).per(30).find_with_reputation(:votes, :all, order: "votes desc")
Or with the model scope like this:
def self.popular
find_with_reputation(:votes, :all, order: 'votes desc')
end
you could do this:
Micropost.page(params[:page]).per(30).popular
Also, as a side note, your routes file is a little strange with multiple member
blocks, when only one is necessary. I would make it look like this:
resources :microposts, only: [:create, :destroy, :index] do
member do
post :vote
post :retweet
end
end