Sha256: 33bfaf6ee965a636221c1a4ef0c20ff113d74e09d2dd14f7672ed043e2e3c715

Contents?: true

Size: 886 Bytes

Versions: 1

Compression:

Stored size: 886 Bytes

Contents

require "awesome_nested_set"

module PandaCms
  class Post < ApplicationRecord
    self.table_name = "panda_cms_posts"

    has_paper_trail versions: {
      class_name: "PandaCms::PostVersion"
    }

    belongs_to :user, class_name: "PandaCms::User"

    validates :title, presence: true
    validates :slug, presence: true, uniqueness: true, format: {with: /\A[a-z0-9-]+\z/}

    scope :ordered, -> { order(published_at: :desc) }
    scope :with_user, -> { includes(:user) }

    has_rich_text :post_content

    belongs_to :tag, class_name: "PandaCms::PostTag", foreign_key: :post_tag_id

    enum :status, {
      active: "active",
      draft: "draft",
      hidden: "hidden",
      archived: "archived"
    }

    def excerpt(length = 100)
      content.gsub(/<[^>]*>/, "").truncate(length)
    end

    def path
      "/" + PandaCms.posts[:prefix] + slug.to_s
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
panda_cms-0.5.4 app/models/panda_cms/post.rb