首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将activerecord-reputation-system查询与分页相结合

将activerecord-reputation-system查询与分页相结合
EN

Stack Overflow用户
提问于 2012-07-20 04:44:04
回答 2查看 534关注 0票数 3

我使用的是位于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错误。我通常的集合调用如下所示

代码语言:javascript
复制
Post.all.text_search(params[:query]).order("created_at desc").page(params[:page]).per(20)

我正在使用Kaminari进行寻呼。有人知道如何将find_with_reputation方法与其他查询参数组合在一起吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-20 15:58:48

就像普通的活动记录查找器方法:

代码语言:javascript
复制
Post.page(params[:page]).per(20).find_with_reputation(:reputation_name, :scope, :find_options)

例如,如果您的帖子有reputation votes

代码语言:javascript
复制
Post.page(params[:page]).per(20).find_with_reputation(:votes, :all, {:order => 'votes DESC, created_at DESC'})

这将找到按声誉,创建日期排序的帖子,并对它们进行分页。

您还可以在模型中为该finder创建一个作用域:

代码语言:javascript
复制
def self.most_voted
  find_with_reputation(:votes, :all, {:order => 'votes DESC'})
end

然后使用:

代码语言:javascript
复制
Post.page(params[:page]).per(20).most_voted
票数 3
EN

Stack Overflow用户

发布于 2016-04-13 02:56:28

我找到了另一个解决方案:Using Active Record Reputation System gem, no sorting happens when I sort by votes

代码语言:javascript
复制
@posts = Post.page(params[:page]).reorder('votes desc').find_with_reputation(:votes, :all)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11568996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档