diff options
| author | hukl <contact@smyck.org> | 2009-09-07 17:16:52 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-09-07 17:16:52 +0200 |
| commit | c7d2d1b51ba07fbeabf7c7a0da000b47a692700b (patch) | |
| tree | b3049c6cdb26aa635cfb7c34cfea4c87fb5544ea /app/models | |
| parent | 78391adf0d7c241a6b1385621d98b6972d799d3a (diff) | |
fixed a bug in update_unique_name
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/node.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 318c203..d4979ea 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -111,9 +111,13 @@ class Node < ActiveRecord::Base | |||
| 111 | parent.nil? ? [slug] : parent.path_to_root.push(slug) | 111 | parent.nil? ? [slug] : parent.path_to_root.push(slug) |
| 112 | end | 112 | end |
| 113 | 113 | ||
| 114 | def update_unique_name | 114 | def current_unique_name |
| 115 | path = self.path_to_root[1..-1] | 115 | path = path_to_root[1..-1] # excluding root |
| 116 | self.unique_name = path.join("/") | 116 | self.unique_name = path.join("/") |
| 117 | end | ||
| 118 | |||
| 119 | def update_unique_name | ||
| 120 | current_unique_name | ||
| 117 | self.save | 121 | self.save |
| 118 | end | 122 | end |
| 119 | 123 | ||
| @@ -145,11 +149,8 @@ class Node < ActiveRecord::Base | |||
| 145 | 149 | ||
| 146 | def check_for_changed_slug | 150 | def check_for_changed_slug |
| 147 | if parent and changed.include? "slug" | 151 | if parent and changed.include? "slug" |
| 148 | self.update_unique_name | 152 | self.unique_name = current_unique_name |
| 149 | 153 | self.descendants.each { |descendant| descendant.update_unique_name } | |
| 150 | if tmp_descendants = descendants | ||
| 151 | tmp_descendants.each { |descendant| descendant.update_unique_name } | ||
| 152 | end | ||
| 153 | end | 154 | end |
| 154 | end | 155 | end |
| 155 | end | 156 | end |
