![](/img/trans.png)
[英]Activerecord-reputation-system - how to check value of current_user's vote
[英]Activerecord-reputation-system Rails gem how to sort by votes and recency of vote?
我正在为Rails使用Activerecord-信誉系统gem。
Product
模型中按其得分(信誉)排序的所有产品。 您当然可以手动对集合进行排序:
@products.sort! {|p1, p2| p1.reputation_for(:votes) <=> p2.reputation_for(:votes)}
就个人而言,我更喜欢使用范围/联接驱动的方式来执行此操作,以使操作数保持ActiveRecord :: Association。
Products.find_with_reputation(:votes, :all, {:order => 'votes DESC'})
或使用范围:
def self.most_voted
find_with_reputation(:votes, :all, {:order => 'votes DESC'})
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.