Sha256: 60b33264d517ffb0410fe16dbe5e7e82d541ec37034da25303a7a91ecb9b1a8f

Contents?: true

Size: 804 Bytes

Versions: 6

Compression:

Stored size: 804 Bytes

Contents

module Pulitzer
  class Post < ActiveRecord::Base
    extend ::FriendlyId
    has_many :versions
    belongs_to :post_type
    delegate :post_type_content_element_types, to: :post_type
    delegate :content_elements, :post_tags, to: :active_version, allow_nil: true
    friendly_id :title, use: [:slugged, :finders]
    after_create :create_preview_version

    TAG_MODELS = ["Pulitzer::Tag"] + Pulitzer.tagging_models

    def content_element(label)
      self.content_elements.find_by(label: label)
    end

    def should_generate_new_friendly_id?
      new_record? || title_changed?
    end

    def active_version
    	versions.active.last
    end

    def preview_version
    	versions.preview.last
    end

    def create_preview_version
      versions.create(status: :preview)
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pulitzer-0.1.7 app/models/pulitzer/post.rb
pulitzer-0.1.6 app/models/pulitzer/post.rb
pulitzer-0.1.5 app/models/pulitzer/post.rb
pulitzer-0.1.4 app/models/pulitzer/post.rb
pulitzer-0.1.3 app/models/pulitzer/post.rb
pulitzer-0.1.2 app/models/pulitzer/post.rb