Skip to content

Instantly share code, notes, and snippets.

@dummied
Created July 26, 2009 01:12
Show Gist options
  • Save dummied/155383 to your computer and use it in GitHub Desktop.
Save dummied/155383 to your computer and use it in GitHub Desktop.
def self.find_popular(args = {})
find(:all, :select => 'tags.*, count(*) as popularity',
:limit => args[:limit] || 10,
:joins => "JOIN taggings ON taggings.tag_id = tags.id JOIN things on taggings.taggable_id = things.id",
:conditions => args[:conditions],
:group => "taggings.tag_id",
:order => "popularity DESC" )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment