def find_all_with_count self.find_by_sql("SELECT t.*, COUNT(pt.post_id) AS count FROM tags t, posts_tags pt WHERE pt.tag_id = t.id GROUP BY t.id ORDER BY count DESC;") end
This is a basic non-specific overview of all tags, as you would see on Snippets' front page. So:
@tag_info = Tag.find_all_with_count @tag_info.each { |t| .. you now have t.name, t.count, etc .. }