Act As Taggable plugin

Plugin details

This ActiveRecord acts-as mixin provides an easy way for addind tagging capabilities (also known as folksnomy) to your ActiveRecord objects. It allows you to apply tags to your objects as well as search for tagged objects.

Websitehttp://wiki.rubyonrails.com/rails/pages/ActsAsTaggablePluginHowto Repositorysvn://rubyforge.org/var/svn/taggable/trunk Author Dirk Elmendorf Tags tag LicenseRuby's (MIT)

Documentation

Install the plugin:
ruby script/plugin install svn://rubyforge.org/var/svn/taggable/trunk

To use the acts_as_taggable mixin with your ActiveRecord objects, you must use a normalized database schema for tagging (also know as folksnomies).

This means that you must have a table solely for holding tag names. Usually, this table is named 'tags' having at least 2 columns: primary key (usually an autoincrement integer called 'id' - the AR standard for PKs) and a 'name' columns, usually a varchar. You must also have a defined ActiveRecord model class that relates to this table, by default called 'Tag'.

For associating tags to your objects you also must have join tables that are composed of at least 2 columns: the tags table foreign key (by default 'tag_id') and your taggable object table foreign key.

If youre using the simple has_and_belongs_to_many model, you must NOT have a primary key (usually an 'id' column) defined on the join table. If youre using a full join model, you must add a primary key column to the join table. Please see the RDoc documentation on acts_as_taggable macro and the :join_class_name option for the differences between these two approaches.

For example, suppose you are tagging photos and you hold your photo data thru the Photo model and on the 'photos' table. Your database schema would look something like this (example suited for MySQL):

CREATE TABLE `tags` (                    
          `id` int(11) NOT NULL auto_increment,  
          `name` varchar(255) default NULL,      
          PRIMARY KEY  (`id`)                    
        )

CREATE TABLE `photos_tags` (                    
          `tag_id` int(11) NOT NULL,  
          `photo_id` int(11) NOT NULL      
        )

CREATE TABLE `photos` (                              
          `id` int(11) NOT NULL auto_increment,              
          `title` varchar(255) default NULL,                 
          `author_name` varchar(255) default NULL,           
          `image_path` varchar(255) default NULL,                   
          PRIMARY KEY  (`id`)                                
        )                


You would normally define 2 models to relate to these tables:

class Tag < ActiveRecord::Base
end

class Photo < ActiveRecord::Base
  acts_as_taggable
end


Now you can easily apply and search for tags on photos in your Rails application.

This assumes youre using only default naming conventions. For using the mix-in with non-standard naming conventions, please see the proper RDoc documentation.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (2 older versions) | Last edited by: scott, 7 months ago