diff --git a/app/models/item.rb b/app/models/item.rb index a8f4f9c0..92e25874 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -5,7 +5,8 @@ class Item key :_type, String key :name, String, :required => true, :index => true - + key :full_name, String, :required => true, :index => true + key :parent_name, String, :index => true key :parent_id, ObjectId, :index => true @@ -15,7 +16,7 @@ class Item key :is_published, Boolean, :required => true, :default => true, :index => true validates_format_of :name, :with => /^[a-zA-Z-_]+$/ - validates_uniqueness_of :name + validates_uniqueness_of :name, :scope => :parent_id belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id many :children, :class_name => "Item", :foreign_key => :parent_id, :dependent => :destroy @@ -32,6 +33,12 @@ class Item nodes.reverse end + def url + urls = ancestors.map{ |a| a.name } << self.name + urls.delete("root") + "/#{urls.join("/")}" + end + protected def setup_default_value diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 688bf945..472c2a03 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -3,6 +3,8 @@ class Snippet include MongoMapper::Document key :name, String, :required => true, :index => true + key :full_name, String, :required => true, :index => true + key :parent_name, String, :required => true, :index => true key :parent_id, ObjectId, :required => true, :index => true diff --git a/app/views/admin/items/_component.html.erb b/app/views/admin/items/_component.html.erb index 4f07f2ae..1ec404bd 100644 --- a/app/views/admin/items/_component.html.erb +++ b/app/views/admin/items/_component.html.erb @@ -5,7 +5,7 @@