我使用的是位于https://github.com/twitter/activerecord-reputation-system的activerecord-reputation系统gem。在我的应用程序中,我希望使用
ActiveRecord::Base.find_with_reputation(:reputation_name, :scope, :find_options)
来自gem的方法。我也有足够的帖子,我需要他们是分页和搜索。但是,每当我调用正常在post集合上工作的页面或搜索方法时,我都会得到一个method I not exist错误。我通常的集合调用如下所示
Post.all.text_search(params[:query]).order("created_at desc").page(params[:page]).per(20)我正在使用Kaminari进行寻呼。有人知道如何将find_with_reputation方法与其他查询参数组合在一起吗?
发布于 2012-07-20 15:58:48
就像普通的活动记录查找器方法:
Post.page(params[:page]).per(20).find_with_reputation(:reputation_name, :scope, :find_options)例如,如果您的帖子有reputation votes
Post.page(params[:page]).per(20).find_with_reputation(:votes, :all, {:order => 'votes DESC, created_at DESC'})这将找到按声誉,创建日期排序的帖子,并对它们进行分页。
您还可以在模型中为该finder创建一个作用域:
def self.most_voted
find_with_reputation(:votes, :all, {:order => 'votes DESC'})
end然后使用:
Post.page(params[:page]).per(20).most_voted发布于 2016-04-13 02:56:28
我找到了另一个解决方案:Using Active Record Reputation System gem, no sorting happens when I sort by votes
@posts = Post.page(params[:page]).reorder('votes desc').find_with_reputation(:votes, :all)https://stackoverflow.com/questions/11568996
复制相似问题