diff options
| -rw-r--r-- | app/models/node.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 4bc8ed4..a870a3a 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -13,6 +13,7 @@ class Node < ActiveRecord::Base | |||
| 13 | # Callbacks | 13 | # Callbacks |
| 14 | after_create :initialize_empty_page | 14 | after_create :initialize_empty_page |
| 15 | before_save :check_for_changed_slug | 15 | before_save :check_for_changed_slug |
| 16 | after_save :update_unique_names_of_children | ||
| 16 | 17 | ||
| 17 | # Validations | 18 | # Validations |
| 18 | # validates_length_of :slug, :within => 3..40 | 19 | # validates_length_of :slug, :within => 3..40 |
| @@ -151,7 +152,15 @@ class Node < ActiveRecord::Base | |||
| 151 | def check_for_changed_slug | 152 | def check_for_changed_slug |
| 152 | if parent and changed.include? "slug" | 153 | if parent and changed.include? "slug" |
| 153 | self.unique_name = current_unique_name | 154 | self.unique_name = current_unique_name |
| 154 | self.descendants.each { |descendant| descendant.update_unique_name } | 155 | end |
| 156 | end | ||
| 157 | |||
| 158 | # Watch out recursion ahead! update_unique_name itself triggers this | ||
| 159 | # after_save callback which invokes update_unique_name on its children. | ||
| 160 | # Hopefully until no childrens occur | ||
| 161 | def update_unique_names_of_children | ||
| 162 | self.descendants.each do |descendant| | ||
| 163 | descendant.update_unique_name | ||
| 155 | end | 164 | end |
| 156 | end | 165 | end |
| 157 | end | 166 | end |
