Skip to content

Commit 7e33844

Browse files
committed
Tutorials are acting as taggable
1 parent 142bc23 commit 7e33844

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class ActsAsTaggableOnMigration < ActiveRecord::Migration
2+
def self.up
3+
create_table :tags do |t|
4+
t.column :name, :string
5+
end
6+
7+
create_table :taggings do |t|
8+
t.column :tag_id, :integer
9+
t.column :taggable_id, :integer
10+
t.column :tagger_id, :integer
11+
t.column :tagger_type, :string
12+
13+
# You should make sure that the column created is
14+
# long enough to store the required class names.
15+
t.column :taggable_type, :string
16+
t.column :context, :string
17+
18+
t.column :created_at, :datetime
19+
end
20+
21+
add_index :taggings, :tag_id
22+
add_index :taggings, [:taggable_id, :taggable_type, :context]
23+
end
24+
25+
def self.down
26+
drop_table :taggings
27+
drop_table :tags
28+
end
29+
end

Diff for: db/schema.rb

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# It's strongly recommended to check this file into your version control system.
1111

12-
ActiveRecord::Schema.define(:version => 20100805033413) do
12+
ActiveRecord::Schema.define(:version => 20100805042131) do
1313

1414
create_table "images", :force => true do |t|
1515
t.integer "parent_id"
@@ -124,6 +124,23 @@
124124
add_index "slugs", ["name", "sluggable_type", "scope", "sequence"], :name => "index_slugs_on_name_and_sluggable_type_and_scope_and_sequence", :unique => true
125125
add_index "slugs", ["sluggable_id"], :name => "index_slugs_on_sluggable_id"
126126

127+
create_table "taggings", :force => true do |t|
128+
t.integer "tag_id"
129+
t.integer "taggable_id"
130+
t.integer "tagger_id"
131+
t.string "tagger_type"
132+
t.string "taggable_type"
133+
t.string "context"
134+
t.datetime "created_at"
135+
end
136+
137+
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
138+
add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
139+
140+
create_table "tags", :force => true do |t|
141+
t.string "name"
142+
end
143+
127144
create_table "tutorials", :force => true do |t|
128145
t.string "title"
129146
t.text "description"

0 commit comments

Comments
 (0)