Sha256: 61e50c43e3af508124dfef8e218c8b216b10a67be5f2b48150b3dbc210f8af2c
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
module Effective class Page < ActiveRecord::Base attr_accessor :current_user acts_as_slugged log_changes if respond_to?(:log_changes) acts_as_role_restricted has_rich_text :body has_many :menu_items, as: :menuable, dependent: :destroy self.table_name = EffectivePages.pages_table_name.to_s effective_resource 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 :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 post.body = body end end def duplicate! duplicate.tap { |page| page.save! } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
effective_pages-3.0.0 | app/models/effective/page.rb |