@@ -10,20 +10,51 @@ Ancestry is a gem/plugin that allows the records of a Ruby on Rails ActiveRecord
10
10
11
11
To apply Ancestry to any ActiveRecord model, follow these simple steps:
12
12
13
- 1. Install
14
- - <b>Rails 2</b>
15
- - See 1-3-stable branch
16
- - <b>Rails 3</b>
17
- - Add to Gemfile: <b>gem 'ancestry'</b>
18
- - Install required gems: <b>bundle install</b>
19
-
20
- 2. Add ancestry column to your table
21
- - Create migration: <b>rails g migration add_ancestry_to_[table] ancestry:string</b>
22
- - Add index to migration: <b>add_index [table], :ancestry</b> (UP) / <b>remove_index [table], :ancestry</b> (DOWN)
23
- - Migrate your database: <b>rake db:migrate</b>
24
-
25
- 3. Add ancestry to your model
26
- - Add to app/models/[model].rb: <b>has_ancestry</b>
13
+ == Install
14
+ === Rails 2
15
+ - See 1-3-stable branch
16
+ === Rails 3
17
+ - Add to Gemfile:
18
+ # Gemfile
19
+
20
+ gem 'ancestry'
21
+ - Install required gems:
22
+ $ bundle install
23
+
24
+ == Add ancestry column to your table
25
+ - Create migration:
26
+ $ rails g migration add_ancestry_to_[table] ancestry:string
27
+ - Add index to migration:
28
+ # db/migrate/[date]_add_ancestry_to_[table].rb
29
+
30
+ class AddAncestryTo[Table] < ActiveRecord::Migration
31
+ # Rails 4 Syntax
32
+ def change
33
+ add_column [table], :ancestry, :string
34
+ add_index [table], :ancestry
35
+ end
36
+
37
+ # Rails 3 Syntax
38
+ def up
39
+ add_column [table], :ancestry, :string
40
+ add_index [table], :ancestry
41
+ end
42
+
43
+ def down
44
+ remove_column [table], :ancestry
45
+ remove_index [table], :ancestry
46
+ end
47
+
48
+ - Migrate your database:
49
+ $ rake db:migrate
50
+
51
+ == Add ancestry to your model
52
+ - Add to app/models/[model].rb:
53
+ # app/models/[model.rb]
54
+
55
+ class [Model] < ActiveRecord::Base
56
+ has_ancestry
57
+ end
27
58
28
59
Your model is now a tree!
29
60
0 commit comments