Sha256: a8b978a22624422b0dabeec6de964ee1ebd237ae70d2d0de3c41df97e21efc02

Contents?: true

Size: 700 Bytes

Versions: 7

Compression:

Stored size: 700 Bytes

Contents

module Brightcontent
  class Page < ActiveRecord::Base
    attr_accessible :body, :name, :parent_id, :hidden
    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

7 entries across 7 versions & 1 rubygems

Version Path
brightcontent-pages-2.0.17 app/models/brightcontent/page.rb
brightcontent-pages-2.0.16 app/models/brightcontent/page.rb
brightcontent-pages-2.0.15 app/models/brightcontent/page.rb
brightcontent-pages-2.0.14 app/models/brightcontent/page.rb
brightcontent-pages-2.0.13 app/models/brightcontent/page.rb
brightcontent-pages-2.0.12 app/models/brightcontent/page.rb
brightcontent-pages-2.0.11 app/models/brightcontent/page.rb