Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created July 29, 2010 22:13
Show Gist options
  • Save sprite2005/499399 to your computer and use it in GitHub Desktop.
Save sprite2005/499399 to your computer and use it in GitHub Desktop.
def popular_tags(limit = nil, order = ' tags.name ASC', gender = 'F', type = nil)
sql = "SELECT tags.id, tags.name, count(*) AS count FROM taggings, tags WHERE tags.id = taggings.tag_id "
sql += " AND taggings.taggable_type = '#{type}'" unless type.nil?
sql += " AND taggings.taggable_type != 'Listing'"
sql += " AND taggings.tagging_user_type = 'Vendor'"
sql += " AND taggings.tagging_user_gender = '#{gender}'"
sql += " GROUP BY tag_id"
sql += " ORDER BY #{order}"
sql += " LIMIT #{limit}" if limit
Tag.find_by_sql(sql).sort{ |a,b| a.name.downcase <=> b.name.downcase}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment