结合ActiveRecord的声誉系统查询分页 [英] Combining activerecord-reputation-system queries with paging
问题描述
我使用设在这里ActiveRecord的声誉系统宝石 https://github.com/叽叽喳喳/ ActiveRecord的声誉系统。在我的应用我有我想要票使用排序职位
I am using the activerecord-reputation-system gem located here https://github.com/twitter/activerecord-reputation-system. In my application I have posts which I want to sort by votes using the
的ActiveRecord :: Base.find_with_reputation(:reputation_name,:范围:find_options)
这是创业板的方法。我也有足够的职位,我需要他们进行分页和搜索。然而,每当我打电话,通常在我的岗位收集工作的网页或搜索方法,我得到一个方法不存在错误。我平时收集调用看起来像这样
method from the gem. I also have enough posts that I need them to be paged and searchable. However whenever I call the page or search methods that normally work on my post collection I get a method does not exist error. My usual collection call looks like this
Post.all.text_search(params[:query]).order("created_at desc").page(params[:page]).per(20)
我使用的雷分页。有谁知道如何在find_with_reputation方法与其他查询参数相结合?
I am using Kaminari for paging. Does anyone know how to combine the find_with_reputation method with other query parameters?
推荐答案
像一个正常的活动记录查找方法:
Like a normal Active Record finder method:
Post.page(params[:page]).per(20).find_with_reputation(:reputation_name, :scope, :find_options)
例如,如果您的文章有声望票
:
For example, if your post has reputation votes
:
Post.page(params[:page]).per(20).find_with_reputation(:votes, :all, {:order => 'votes DESC, created_at DESC'})
这将找到的帖子订购的信誉,创建日期和分页他们。
This will find posts ordered by reputation, creation date and paginate them.
您还可以在模型的发现者创建范围:
You can also create a scope in your model for that finder:
def self.most_voted
find_with_reputation(:votes, :all, {:order => 'votes DESC'})
end
然后使用:
Post.page(params[:page]).per(20).most_voted
这篇关于结合ActiveRecord的声誉系统查询分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!