Fixed Item#parent_name

This commit is contained in:
Wen-Tien Chang committed 2010-02-22 15:27:11 +08:00
1 parent 9fa03db2c0
commit f9b1618ac7
4 files changed
+16 -8

No files matched your search

+2 -2
View File
@@ -5,14 +5,14 @@ class Admin::ItemsController < ApplicationController
before_filter :find_snippets, :only => :index
def index
@items = Item.all( :conditions => { :parent_name => @parent_item.name } )
@items = Item.all( :conditions => { :parent_id => @parent_item.id } )
@items.unshift Item.find_by_name("root") if @parent_item.name == 'root'
end
protected
def find_snippets
@snippets = Snippet.all( :conditions => { :parent_name => @parent_item.name } )
@snippets = Snippet.all( :conditions => { :parent_id => @parent_item.id } )
end
end
+8 -4
View File
@@ -6,8 +6,7 @@ class Item
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
key_i18n :title, String, :required => true
@@ -15,14 +14,19 @@ class Item
key :position, Integer, :required => true
key :is_published, Boolean, :required => true, :default => true, :index => true
validates_format_of :name, :with => /^[a-zA-Z\-_]+$/
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
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
before_validation :setup_default_value
attr_writer :parent_name
def parent_name
self.parent.name
end
def self.find_by_name(item_name)
Item.find(:first, :conditions => { :name => item_name, :is_published => true })
end
+5 -1
View File
@@ -5,7 +5,6 @@ class Snippet
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
key_i18n :content, String
@@ -15,6 +14,11 @@ class Snippet
belongs_to :parent, :class_name => "Snippet", :foreign_key => :parent_id
attr_writer :parent_name
def parent_name
self.parent.name
end
protected
def ancestors