Acts As Taggable On Steroids

This plugin is based on acts_as_taggable by DHH but includes extras such as tests, smarter tag assignment, and tag cloud calculations.

Thanks to www.fanacious.com for allowing this plugin to be released. Please check out their site to show your support.

Resources

Install script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids

Usage

=== Basic tagging

Using the examples from the tests, let’s suppose we have users that have many posts and we want those posts to be able to be tagged by the user.

As usual, we add acts_as_taggable to the Post class:

class Post < ActiveRecord::Base
  acts_as_taggable
end
belongs_to :user

We can now use the tagging methods provided by acts_as_taggable, tag_list and tag_list=. Both these methods work like regular attribute accessors.

p = Post.find(:first)
p.tag_list # "" 
p.tag_list = "Funny, Silly" 
p.save
p.reload.tag_list # "Funny, Silly"

=== Tag cloud calculations

To construct tag clouds, the frequency of each tag needs to be calculated. Because we specified acts_as_taggable on the Post class, we can get a calculation of all the tag counts by using Post.tag_counts. But what if we wanted a tag count for an individual user’s posts? To achieve this we extend the :posts association like so:

class User < ActiveRecord::Base
  has_many :posts, :extend => TagCountsExtension
end

This extension now allows us to do the following:

User.find(:first).posts.tag_counts

This can be used to construct a tag cloud for the posts of an individual user. The TagCountsExtension should only be used on associations that have acts_as_taggable defined.

== Credits

www.fanacious.com

Tags

Currently tagged with: activerecord, acts_as, folksonomy
You need to Login to tag this item.