ssoper (owner)

Revisions

  • 33b2d1 ssoper Thu Oct 29 19:50:40 -0700 2009
  • 31539a ssoper Thu Oct 29 19:50:21 -0700 2009
gist: 222067 Download_button fork
public
Description:
Throw this in your config/initializers dir for some hot tag cloud action using the is_taggable gem
Public Clone URL: git://gist.github.com/222067.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Throw this in your config/initializers dir for some hot tag cloud action using the is_taggable gem
 
module TaggableExtensions
  
  def tag_cloud
    result = self.find_by_sql <<-SQL
SELECT tags.id as tag_id, tags.name as tag_name, count(taggings.tag_id) as tag_count
FROM tags, taggings
WHERE tags.id = taggings.tag_id AND taggings.taggable_type = "#{self}"
GROUP BY (taggings.tag_id)
SQL
    result.collect(&:attributes)
  end
  
end
 
ActiveRecord::Base.send(:extend, TaggableExtensions)