Navigation Menu

Skip to content

Commit

Permalink
Added :conditions argument to #plusminus_tally.
Browse files Browse the repository at this point in the history
  • Loading branch information
bouchard committed Dec 31, 2011
1 parent d2e6369 commit 9762762
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/acts_as_voteable.rb
Expand Up @@ -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!

Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit 9762762

Please sign in to comment.