Commit 8ef8336

mo khan <mo@mokhan.ca>
2013-06-22 17:53:34
mount tags onto need
1 parent f5af1b4
app/models/need.rb
@@ -1,4 +1,5 @@
 class Need < ActiveRecord::Base
   belongs_to :user
   attr_accessible :description, :user_id
+  acts_as_taggable
 end
db/migrate/20130622175108_acts_as_taggable_on_migration.rb
@@ -0,0 +1,30 @@
+class ActsAsTaggableOnMigration < ActiveRecord::Migration
+  def self.up
+    create_table :tags do |t|
+      t.string :name
+    end
+
+    create_table :taggings do |t|
+      t.references :tag
+
+      # You should make sure that the column created is
+      # long enough to store the required class names.
+      t.references :taggable, :polymorphic => true
+      t.references :tagger, :polymorphic => true
+
+      # Limit is created to prevent MySQL error on index
+      # length for MyISAM table type: http://bit.ly/vgW2Ql
+      t.string :context, :limit => 128
+
+      t.datetime :created_at
+    end
+
+    add_index :taggings, :tag_id
+    add_index :taggings, [:taggable_id, :taggable_type, :context]
+  end
+
+  def self.down
+    drop_table :taggings
+    drop_table :tags
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130622170818) do
+ActiveRecord::Schema.define(:version => 20130622175108) do
 
   create_table "needs", :force => true do |t|
     t.text     "description"
@@ -20,6 +20,23 @@ ActiveRecord::Schema.define(:version => 20130622170818) do
     t.datetime "updated_at",  :null => false
   end
 
+  create_table "taggings", :force => true do |t|
+    t.integer  "tag_id"
+    t.integer  "taggable_id"
+    t.string   "taggable_type"
+    t.integer  "tagger_id"
+    t.string   "tagger_type"
+    t.string   "context",       :limit => 128
+    t.datetime "created_at"
+  end
+
+  add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
+  add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
+
+  create_table "tags", :force => true do |t|
+    t.string "name"
+  end
+
   create_table "users", :force => true do |t|
     t.string   "email",                  :default => "", :null => false
     t.string   "encrypted_password",     :default => "", :null => false