Created
July 29, 2010 22:13
-
-
Save sprite2005/499399 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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