You are here: Browse Railsplugins Acts As Taggable On Steroids
= acts_as_taggable_on_steroids
If you find this plugin useful, please consider a donation to show your support!
http://www.paypal.com/cgi-bin/webscr?cmd=_send-money
Email address: jonathan.viney@gmail.com
Instructions
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.
ResourcesInstall * script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids
Usage = Basic taggingUsing 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"
=== Finding tagged objects
To retrieve objects tagged with a certain tag, use find_tagged_with.
Post.find_tagged_with('Funny, Silly')
By default, find_tagged_with will find objects that have any of the given tags. To find only objects that are tagged with all the given tags, use match_all.
Post.find_tagged_with('Funny, Silly', :match_all => true)
=== 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.
Problems, comments, and suggestions all welcome. jonathan.viney@gmail.com
== Credits
www.fanacious.com
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly