From 7edc07cb016bebb9b6c06e105f88f595d5ad00c3 Mon Sep 17 00:00:00 2001 From: hukl Date: Thu, 29 Jan 2009 22:30:00 +0100 Subject: added generation of unique names based on the position on the tree after adding a node as a children of another node --- app/models/node.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/models/node.rb') 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 @@ class Node < ActiveRecord::Base acts_as_nested_set + + # returns array with pages up to root excluding root + def path_to_root + parent.nil? && [slug] || parent.path_to_root.push(slug) + end + + def update_unique_name + path = self.path_to_root[1..-1] + self.unique_name = path.join("/") + end end -- cgit v1.3