From 9762762a109e3d62630c43272862e97946c737c0 Mon Sep 17 00:00:00 2001 From: Brady Bouchard Date: Fri, 30 Dec 2011 22:06:33 -0700 Subject: [PATCH] Added :conditions argument to #plusminus_tally. --- lib/acts_as_voteable.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/acts_as_voteable.rb b/lib/acts_as_voteable.rb index 0a3ef07..3fab614 100644 --- a/lib/acts_as_voteable.rb +++ b/lib/acts_as_voteable.rb @@ -27,6 +27,7 @@ module SingletonMethods # :ascending - Default false - normal order DESC (i.e. highest rank to lowest) # :at_least - Default 1 - Item must have at least X votes # :at_most - Item may not have more than X votes + # :conditions - (string) Extra conditions, if you'd like. def plusminus_tally(*args) options = args.extract_options! @@ -56,6 +57,7 @@ def plusminus_tally(*args) t = t.where("joined_#{Vote.table_name}.voteable_type = '#{self.name}'") t = t.where("joined_#{Vote.table_name}.created_at >= ?", options[:start_at]) if options[:start_at] t = t.where("joined_#{Vote.table_name}.created_at <= ?", options[:end_at]) if options[:end_at] + t = t.where(options[:conditions]) if options[:conditions] t = options[:ascending] ? t.order("joined_#{Vote.table_name}.vote_total") : t.order("joined_#{Vote.table_name}.vote_total DESC") t = t.having([