Sha256: 07ef45ecc63eaa838e082523933f5dcbc5a746e3c177c52d2e9e9a5f83421fcf

Contents?: true

Size: 692 Bytes

Versions: 2

Compression:

Stored size: 692 Bytes

Contents

module Brightcontent
  class Page < ActiveRecord::Base
    attr_accessible :body, :name, :parent_id

    acts_as_nested_set
    include Brightcontent::Attachable

    validates_presence_of :name
    after_save :update_slug

    def self.default_scope
      order(:lft)
    end

    def homepage?
      lft == 1
    end

    def attachment_styles
      Brightcontent.page_attachment_styles
    end

    def root_parent_children
      root? ? children : ancestors.first.children
    end

    private

    def update_slug
      self.update_column(:slug, slug_name)
    end

    def slug_name
      homepage? ? "" : self_and_ancestors.map { |p| p.name.parameterize }.join("/")
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brightcontent-pages-2.0.10 app/models/brightcontent/page.rb
brightcontent-pages-2.0.9 app/models/brightcontent/page.rb