summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-09-09 15:18:09 +0200
committerhukl <contact@smyck.org>2009-09-09 15:18:09 +0200
commitf3a8cd8d1e8dfafb987163d95208e0ff2ccbfbc2 (patch)
treed93631a0c8277f0f52bd2ba9c8ab4c9c94195420
parent3fb1e130b9428235e73a7b530761b9cd438d7f80 (diff)
fixed yet another bug when editing slugs or moving nodes
-rw-r--r--app/models/node.rb11
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
157end 166end