Acts As Taggable Plugin

The first Ruby on Rails plugin that I used was acts_as_taggable. With the acts_as_taggable plugin you can tag instances of your models in the same fashion you tag your pictures on Flickr or your bookmarks on Del.icio.us. Just to create some confusion there are two version of the the acts_as_taggable functionality. One is available as a gem while the other is a plugin. I’ll be covering the plugin here.

The taggable how-to wiki page on the rubyonrails.org has great information on how to get started with the acts_as_taggable plugin. In particular the wiki will walk you through the installation process and the creation of the tables necessary to store the tags. Once you get the plugin installed all you have to do is make your model act as taggable:

class Post < ActiveRecord::Base
  acts_as_taggable
end

In your controller you can tag a post with these siple lines of ruby code:

post = Post.find(params[:id])
post.tag_with('tag1 tag2 tag3')

To retrieve the tags for a post, as a single string, use the tag_list method. To get the tags as a list use the tags property. You can also find all posts marked with a given tag, for example:

posts = Post.find_tagged_with('tag1')

This plugin is easy to use and easy to learn from. I’ve written several ActiveRecord plugins that use this plugin as a template and now my most of my models act as taggable, commentable, versionable, rateable, etc.

Technorati Tags: , , , , , ,

Enjoy. Share. Be Happy.
  • Twitter
  • Facebook
  • StumbleUpon
  • del.icio.us
  • Tumblr
  • Google Bookmarks
  • FriendFeed
  • Yahoo! Buzz
  • Reddit
  • Digg
  • HackerNews
  • Suggest to Techmeme via Twitter
  • LinkedIn
  • Ping.fm
  • Identi.ca
  • Mixx
  • Furl

Related posts:

  1. Acts As Taggable Conditions Hack
  2. Acts As Bookmarkable Plugin
  3. Acts As Taggable Tag Cloud
  4. Acts As Rateable Plugin
  5. Acts As Voteable Rails Plugin

This entry was posted in Ruby, TechKnow. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. basil
    Posted April 30, 2007 at 7:59 am | Permalink

    This is a cool plugin

  2. Alex
    Posted August 12, 2008 at 6:05 pm | Permalink

    Hi, I have a question.

    I want to know if this plugin is good for my app, so:

    I have a table BLOG with the fields: subject, body, created_at
    and i have another table LINKABLES with this field: keyword

    I want the words that are in the blog body can be links (taking of reference the keywords from the table LINKABLES)

    Can i do that with this plugin?

2 Trackbacks

  1. By Rails Plugins on July 28, 2007 at 3:01 pm

    [...] than acts_as_taggable, I use actsas_taggableonsteroids, which is based on acts_as_taggable. Neither supports multiple [...]

  2. [...] acts_as_taggable ??????????????? tagging [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*