Sha256: 1b2c29b9762bebbd08ac8493e92ef5b93a950005256e73c067badb1b6da30d63
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
module Kms class Page < ActiveRecord::Base include Liquor::Dropable include CompileTemplates include Positioned INDEX_SLUG = "index".freeze INDEX_FULLPATH = "" scope :published, lambda { where(published: true) } scope :listed, lambda { where(hidden: false) } scope :not_templatable, lambda { where(templatable: false) } belongs_to :template validates :slug, uniqueness: true, presence: true before_save :build_fullpath has_ancestry def index? slug == INDEX_SLUG end def build_fullpath if index? self.fullpath = INDEX_FULLPATH # self.slug else slugs = (ancestors + [self]).map(&:slug) slugs.shift unless slugs.size == 1 self.fullpath = File.join slugs.compact end end # fetch items for templatable page def fetch_items templatable_type.constantize.all end # fetch item by slug def fetch_item!(slug) return nil unless templatable? templatable_type.constantize.find_by_slug!(slug) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kms-0.9.0 | app/models/kms/page.rb |