Title: Using Tagging in your Ruby on Rails Application Post by: Mark David on March 16, 2007, 02:10:40 PM Using Tagging in your Ruby on Rails Application
Tagging is all the rage in the web 2.0 universe. For you aspiring Ruby on Rails developers, you are in luck, because there is a great plugin that makes adding tagging into your application a breeze. This recipe describes using the acts_as_taggable plugin on Rails 1.1 To install the plugin into your application, you will first run these commands from your project directory in your console: Code: script/plugin install acts_as_taggable The first command installs the plugin from the RubyGems repository. The second command generates a Rails Migration file under the db/migrate directory. You will want to open up that file and add in this code: Code: class AddTagSupport < ActiveRecord::Migration Running the next command will execute the file we just edited and create the database support for tags. Code: rake db:migrate Now you need to add the following line to the top of your model class: Code: acts_as_taggable And that's it. You now have tagging support on your object! Here are some sample usage for you to try: Code: # tags a post with both the tags "Agile" and "Rails" |