2010-04-25 00:33:38 +00:00
|
|
|
class PagePart
|
|
|
|
include Mongoid::Document
|
|
|
|
|
|
|
|
## fields ##
|
|
|
|
field :name, :type => String
|
|
|
|
field :slug, :type => String
|
|
|
|
field :value, :type => String
|
|
|
|
field :disabled, :type => Boolean, :default => false
|
2010-05-09 12:44:53 +00:00
|
|
|
field :value, :type => String
|
2010-04-25 00:33:38 +00:00
|
|
|
|
|
|
|
## associations ##
|
|
|
|
embedded_in :page, :inverse_of => :parts
|
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
## callbacks ##
|
2010-05-09 12:44:53 +00:00
|
|
|
# before_validate { |p| p.slug ||= p.name.slugify if p.name.present? }
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-04-25 00:33:38 +00:00
|
|
|
## validations ##
|
|
|
|
validates_presence_of :name, :slug
|
|
|
|
|
2010-05-09 12:44:53 +00:00
|
|
|
## named scopes ##
|
|
|
|
named_scope :enabled, where(:disabled => false)
|
|
|
|
|
|
|
|
## methods ##
|
|
|
|
|
|
|
|
def self.build_body_part
|
2010-05-10 22:39:52 +00:00
|
|
|
self.new({
|
|
|
|
:name => I18n.t('attributes.defaults.page_parts.name'),
|
|
|
|
:value => I18n.t('attributes.defaults.pages.other.body'),
|
|
|
|
:slug => 'layout'
|
|
|
|
})
|
2010-05-09 12:44:53 +00:00
|
|
|
end
|
2010-04-25 00:33:38 +00:00
|
|
|
end
|