1

Rails 用の Activerecord-reputation-system gem を使用しています。

  1. Productスコア(評判)でソートされたモデルからすべての製品を呼び出したいと思います。
  2. また、評判を期間で制限する方法を教えてください。すべての製品を先月のみの投票で並べ替えたいとしましょう。
4

1 に答える 1

0

もちろん、コレクションを手動で並べ替えることができます。

@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
于 2013-06-26T23:48:54.203 に答える