rubygems - Activerecord-reputation-system Rails gem how to sort by votes and recency of vote? -
i'm using activerecord-reputation-system gem rails.
- i call products
product
model sorted score(reputation). - could tell me how can limit reputation time period - let's want sort products votes happened in last month only.
you can manually sort collection, of course:
@products.sort! {|p1, p2| p1.reputation_for(:votes) <=> p2.reputation_for(:votes)}
personally, prefer scope/join driven way allow operand stay activerecord::association.
products.find_with_reputation(:votes, :all, {:order => 'votes desc'})
or using scope:
def self.most_voted find_with_reputation(:votes, :all, {:order => 'votes desc'}) end
Comments
Post a Comment