Add Page position and parent_page_id
This commit is contained in:
1 parent
96f186a71b
commit
a4c900af4d
6 files changed
+70
-33
No files matched your search
+21
-1
@@ -1,16 +1,23 @@
|
||||
class Page < CouchFoo::Base
|
||||
|
||||
property :name, String
|
||||
property :parent_name, String
|
||||
property :parent_page_id, String
|
||||
property :content, String
|
||||
property :layout_id, String
|
||||
property :layout_name, String
|
||||
property :position, Integer
|
||||
property :is_published, Boolean
|
||||
|
||||
belongs_to :layout
|
||||
has_many :children, :class_name => 'Page', :foreign_key => 'parent_page_id'
|
||||
|
||||
validates_presence_of :name
|
||||
validates_presence_of :position
|
||||
|
||||
before_save :setup_layout_id
|
||||
before_validation :setup_default_value
|
||||
|
||||
default_sort :position
|
||||
|
||||
def setup_layout_id
|
||||
if self.layout_name.blank?
|
||||
@@ -20,4 +27,17 @@ class Page < CouchFoo::Base
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def setup_default_value
|
||||
unless self.position
|
||||
max_page = Page.last( :use_key => 'position')
|
||||
self.position = (max_page)? max_page.position.to_i + 1 : 1
|
||||
end
|
||||
|
||||
unless self.parent_page_id
|
||||
self.parent_page_id = "root"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user