Sha256: 26bb98e50a0b0e7180977727ead8c54b226b09e3f30a576ff56a83c66eb51b67

Contents?: true

Size: 943 Bytes

Versions: 54

Compression:

Stored size: 943 Bytes

Contents

module Tenon
  class Post < ActiveRecord::Base
    # Scopes, Attachments, etc.
    default_scope { order('publish_at DESC') }
    scope :posted, -> { where('publish_at <= ?', Time.now) }
    scope :for_archive, ->(year, month) { where(Post.for_archive_conditions(year, month)) }
    tenon_content :content, i18n: true
    has_history includes: [:content_tenon_content_rows]

    # Relationships
    has_and_belongs_to_many :post_categories, class_name: 'Tenon::PostCategory'
    belongs_to :user
    can_have_comments

    # Validations
    validates_presence_of :title

    def to_param
      "#{id}-#{title.parameterize}"
    end

    # previous and next posts for mobile post nav
    def next
      Post.posted.where('publish_at > ?', publish_at).last
    end

    def previous
      Post.posted.where('publish_at < ?', publish_at).first
    end

    def posted?
      publish_at.present? ? publish_at <= Time.now : false
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
tenon-1.1.8 app/models/tenon/post.rb
tenon-1.1.7 app/models/tenon/post.rb
tenon-1.1.6 app/models/tenon/post.rb
tenon-1.1.5 app/models/tenon/post.rb
tenon-1.1.4 app/models/tenon/post.rb
tenon-1.1.3 app/models/tenon/post.rb
tenon-1.1.2 app/models/tenon/post.rb
tenon-1.1.1 app/models/tenon/post.rb
tenon-1.0.76 app/models/tenon/post.rb
tenon-1.0.75 app/models/tenon/post.rb
tenon-1.0.74 app/models/tenon/post.rb
tenon-1.0.73 app/models/tenon/post.rb
tenon-1.0.72 app/models/tenon/post.rb
tenon-1.0.71 app/models/tenon/post.rb
tenon-1.0.70 app/models/tenon/post.rb
tenon-1.0.69 app/models/tenon/post.rb
tenon-1.0.68 app/models/tenon/post.rb
tenon-1.0.67 app/models/tenon/post.rb
tenon-1.0.66 app/models/tenon/post.rb
tenon-1.0.65 app/models/tenon/post.rb