Skip to content

Tagging implementation where you can specify the tagger through a polymorphic association.

License

Notifications You must be signed in to change notification settings

baumicon/polytaggable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polytaggable

Tagging implementation where you can specify the tagger through a polymorphic association.

Usage

class User < ActiveRecord::Base
  acts_as_polytaggable(:tagger => "account")
end
class Account < ActiveRecord::Base
  has_many :tags, :as => :tagger, :dependent => :destroy, :order => "user_friendly_name ASC"
end

Finding users with specific tag

User.tagged_with("awesome")

Creating a new Object

User.create!(:tag_attributes => "awesome anothertag tag3")

Migration

class AddPolytaggable < ActiveRecord::Migration
  def self.up
    create_table "taggings", :force => true do |t|
      t.string   "taggable_type"
      t.datetime "created_at"
      t.integer   "tag_id", :null => true
      t.integer   "taggable_id", :null => true
    end
    
    create_table "tags", :force => true do |t|
      t.string  "name"
      t.string  "name_stem"
      t.integer "taggings_count",                   :default => 0
      t.string  "tagger_type"
      t.string  "user_friendly_name"
      t.integer  "tagger_id", :null => true
    end
    add_index "taggings", ["tag_id", "taggable_id", "taggable_type"], :name => "by_tag_and_poly"
    add_index "taggings", ["taggable_id"], :name => "by_taggable_id"
    
  end

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

About

Tagging implementation where you can specify the tagger through a polymorphic association.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages