rubygems - Activerecord-reputation-system Rails gem how to sort by votes and recency of vote? -


i'm using activerecord-reputation-system gem rails.

  1. i call products product model sorted score(reputation).
  2. 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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -