Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Welcome to the TechnoWorldInc! Community!
Recent Updates
[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 14, 2024, 02:00:39 PM]

[February 08, 2024, 10:26:18 AM]

[February 08, 2024, 10:26:18 AM]

[February 08, 2024, 10:26:18 AM]

[February 08, 2024, 10:26:18 AM]

[November 27, 2023, 06:32:12 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » Others
 Using Tagging in your Ruby on Rails Application
Pages: [1]   Go Down
  Print  
Author Topic: Using Tagging in your Ruby on Rails Application  (Read 3481 times)
Mark David
Administrator
Super Elite Member
*****



Karma: 185
Offline Offline

Posts: 1624

!!!Techno King!!!

fabulous_designer
View Profile WWW
Using Tagging in your Ruby on Rails Application
« Posted: 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
script/generate migration add_tag_support

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
  def self.up
    #Table for your Tags
    create_table :tags do |t|
      t.column :name, :string
    end

    create_table :taggings do |t|
      t.column :tag_id, :integer
      #id of tagged object
      t.column :taggable_id, :integer
      #type of object tagged
      t.column :taggable_type, :string
    end
  end

  def self.down
    drop_table :tags
    drop_table :taggings
  end
end

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"
   post.tag_with("agile rails")

# returns a string containing "agile rails", space delimited.
   post.tag_list     

# find all posts tagged with Rails
   post.find_tagged_with("Rails")

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.083 seconds with 24 queries.