From aaf7f7362ccaeac4bab21588d84bc06243516a03 Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Tue, 7 Jan 2014 17:56:58 +0800 Subject: [PATCH] Fix for submenu automation --- app/models/item.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index 7c5e6433..8f31d723 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -23,7 +23,7 @@ class Item before_destroy :destroy_children after_rearrange :rebuild_path, :if => "parent_id_changed? || name_changed?" - after_save :rebuild_children_path, :rebuild_parent_path, :if => "path_changed?" + after_save :rebuild_children_path, :rebuild_page_children_path, :if => "path_changed?" def enabled_for_lang(lang) enabled_for.include?(lang) rescue false @@ -92,9 +92,13 @@ class Item end end - def rebuild_parent_path - parent = self.parent - parent.descendants_and_self +def rebuild_page_children_path + page = Page.find(self.id) + page.children.each do |child| + child.path = (child.ancestors_and_self - [Page.root]).collect{|x| x.name}.join('/') + child.save + child.rebuild_children_path + end end # Enable the validation for parent_id