Skip to content

Instantly share code, notes, and snippets.

@peteonrails
Forked from ravicious/acts_as_voteable.rb
Created July 6, 2009 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peteonrails/141505 to your computer and use it in GitHub Desktop.
Save peteonrails/141505 to your computer and use it in GitHub Desktop.
def tally(options = {})
find(:all, options_for_tally(options.merge({:order =>"count DESC" })))
end
>> s1 = Status.tally({
?> :at_least => 1,
?> :order => 'status.created_at desc' }) # DESC
>> s2 = Status.tally({
?> :at_least => 1,
?> :order => 'status.created_at asc' }) # ASC
>> s1[0].created_at == s2[0].created_at
=> true
>> s1.each {|x| puts x.votes_count}
2
2
2
2
1
1
>> s2.each {|x| puts x.votes_count}
2
2
2
2
1
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment