diff options
Diffstat (limited to 'app/models/node.rb')
| -rw-r--r-- | app/models/node.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 82183c9..e2ff973 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | class Node < ActiveRecord::Base | 1 | class Node < ActiveRecord::Base |
| 2 | acts_as_nested_set | 2 | acts_as_nested_set |
| 3 | |||
| 4 | # returns array with pages up to root excluding root | ||
| 5 | def path_to_root | ||
| 6 | parent.nil? && [slug] || parent.path_to_root.push(slug) | ||
| 7 | end | ||
| 8 | |||
| 9 | def update_unique_name | ||
| 10 | path = self.path_to_root[1..-1] | ||
| 11 | self.unique_name = path.join("/") | ||
| 12 | end | ||
| 3 | end | 13 | end |
