Skip to content

Commit 0940890

Browse files
committed
```ruby doesn't also need indentation
1 parent 2c82dff commit 0940890

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

README.md

+51-51
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,35 @@ Note that closure_tree is being developed for Rails 3.1.x
2323

2424
Note that if the column is null, the tag will be considered a root node.
2525

26-
```ruby
27-
class AddParentIdToTag < ActiveRecord::Migration
28-
def change
29-
add_column :tag, :parent_id, :integer
30-
end
26+
```ruby
27+
class AddParentIdToTag < ActiveRecord::Migration
28+
def change
29+
add_column :tag, :parent_id, :integer
3130
end
32-
```
31+
end
32+
```
3333

3434
5. Add a database migration to store the hierarchy for your model. By
3535
convention the table name will be the model's table name, followed by
3636
"_hierarchy". Note that by calling ```acts_as_tree```, a "virtual model" (in this case, ```TagsHierarchy```) will be added automatically, so you don't need to create it.
3737

38-
```ruby
39-
class CreateTagHierarchies < ActiveRecord::Migration
40-
def change
41-
create_table :tag_hierarchies, :id => false do |t|
42-
t.integer :ancestor_id, :null => false # ID of the parent/grandparent/great-grandparent/... tag
43-
t.integer :descendant_id, :null => false # ID of the target tag
44-
t.integer :generations, :null => false # Number of generations between the ancestor and the descendant. Parent/child = 1, for example.
45-
end
38+
```ruby
39+
class CreateTagHierarchies < ActiveRecord::Migration
40+
def change
41+
create_table :tag_hierarchies, :id => false do |t|
42+
t.integer :ancestor_id, :null => false # ID of the parent/grandparent/great-grandparent/... tag
43+
t.integer :descendant_id, :null => false # ID of the target tag
44+
t.integer :generations, :null => false # Number of generations between the ancestor and the descendant. Parent/child = 1, for example.
45+
end
4646
47-
# For "all progeny of..." selects:
48-
add_index :tag_hierarchies, [:ancestor_id, :descendant_id], :unique => true
47+
# For "all progeny of..." selects:
48+
add_index :tag_hierarchies, [:ancestor_id, :descendant_id], :unique => true
4949
50-
# For "all ancestors of..." selects
51-
add_index :tag_hierarchies, [:descendant_id]
52-
end
50+
# For "all ancestors of..." selects
51+
add_index :tag_hierarchies, [:descendant_id]
5352
end
54-
```
53+
end
54+
```
5555

5656
6. Run ```rake db:migrate```
5757

@@ -67,39 +67,39 @@ Note that closure_tree is being developed for Rails 3.1.x
6767
6868
Create a root node:
6969
70-
```ruby
71-
grandparent = Tag.create(:name => 'Grandparent')
72-
```
70+
```ruby
71+
grandparent = Tag.create(:name => 'Grandparent')
72+
```
7373
7474
Child nodes are created by appending to the children collection:
7575
76-
```ruby
77-
child = parent.children.create(:name => 'Child')
78-
```
76+
```ruby
77+
child = parent.children.create(:name => 'Child')
78+
```
7979
8080
You can also append to the children collection:
8181
82-
```ruby
83-
child = Tag.create(:name => 'Child')
84-
parent.children << child
85-
```
82+
```ruby
83+
child = Tag.create(:name => 'Child')
84+
parent.children << child
85+
```
8686
8787
Or call the "add_child" method:
8888
89-
```ruby
90-
parent = Tag.create(:name => 'Parent')
91-
grandparent.add_child parent
92-
```
89+
```ruby
90+
parent = Tag.create(:name => 'Parent')
91+
grandparent.add_child parent
92+
```
9393
9494
Then:
9595
96-
```ruby
97-
puts grandparent.self_and_descendants.collect{ |t| t.name }.join(" > ")
98-
"grandparent > parent > child"
96+
```ruby
97+
puts grandparent.self_and_descendants.collect{ |t| t.name }.join(" > ")
98+
"grandparent > parent > child"
9999
100-
child.ancestry_path
101-
["grandparent", "parent", "child"]
102-
```
100+
child.ancestry_path
101+
["grandparent", "parent", "child"]
102+
```
103103
104104
### <code>find_or_create_by_path</code>
105105
@@ -116,9 +116,9 @@ provided to ```acts_as_tree```.
116116
117117
Note that any other AR fields can be set with the second, optional ```attributes``` argument.
118118
119-
```ruby
120-
child = Tag.find_or_create_by_path(%w{home chuck Photos"}, {:tag_type => "File"})
121-
```
119+
```ruby
120+
child = Tag.find_or_create_by_path(%w{home chuck Photos"}, {:tag_type => "File"})
121+
```
122122
This will pass the attribute hash of ```{:name => "home", :tag_type => "File"}``` to
123123
```Tag.find_or_create_by_name``` if the root directory doesn't exist (and
124124
```{:name => "chuck", :tag_type => "File"}``` if the second-level tag doesn't exist, and so on).
@@ -169,14 +169,14 @@ Polymorphic models are supported:
169169
1. Create a db migration that adds a String ```type``` column to your model
170170
2. Subclass the model class. You only need to add acts_as_tree to your base class.
171171
172-
```ruby
173-
class Tag < ActiveRecord::Base
174-
acts_as_tree
175-
end
176-
class WhenTag < Tag ; end
177-
class WhereTag < Tag ; end
178-
class WhatTag < Tag ; end
179-
```
172+
```ruby
173+
class Tag < ActiveRecord::Base
174+
acts_as_tree
175+
end
176+
class WhenTag < Tag ; end
177+
class WhereTag < Tag ; end
178+
class WhatTag < Tag ; end
179+
```
180180
181181
## Change log
182182

0 commit comments

Comments
 (0)