Sha256: ed3ef17686afd149e15878380d0e85812f28ae6ddc3d1722cbe01386b830c78b

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

module Effective
  class Page < ActiveRecord::Base
    acts_as_role_restricted
    acts_as_regionable
    acts_as_slugged

    has_many :menu_items, as: :menuable, dependent: :destroy

    self.table_name = EffectivePages.pages_table_name.to_s

    # structure do
    #   title             :string
    #   meta_description  :string

    #   draft             :boolean

    #   layout            :string
    #   template          :string

    #   slug              :string
    #   roles_mask        :integer

    #   timestamps
    # end

    validates :title, presence: true, length: { maximum: 255 }
    validates :meta_description, presence: true, length: { maximum: 150 }

    validates :layout, presence: true
    validates :template, presence: true

    scope :drafts, -> { where(draft: true) }
    scope :published, -> { where(draft: false) }
    scope :sorted, -> { order(:title) }
    scope :except_home, -> { where.not(title: 'Home') }

    def to_s
      title
    end

    def published?
      !draft?
    end

    # Returns a duplicated post object, or throws an exception
    def duplicate!
      Page.new(attributes.except('id', 'updated_at', 'created_at')).tap do |page|
        page.title = page.title + ' (Copy)'
        page.slug = page.slug + '-copy'
        page.draft = true

        regions.each do |region|
          page.regions.build(region.attributes.except('id', 'updated_at', 'created_at'))
        end

        page.save!
      end
    end

  end

end




Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
effective_pages-2.0.8 app/models/effective/page.rb
effective_pages-2.0.7 app/models/effective/page.rb
effective_pages-2.0.6 app/models/effective/page.rb
effective_pages-2.0.5 app/models/effective/page.rb
effective_pages-2.0.4 app/models/effective/page.rb
effective_pages-2.0.3 app/models/effective/page.rb
effective_pages-2.0.2 app/models/effective/page.rb