Sha256: aab862ffe12a8bba4fb51ccf418037db0f0bd8c8712c475f4f85ea38fe0429aa

Contents?: true

Size: 827 Bytes

Versions: 2

Compression:

Stored size: 827 Bytes

Contents

class NewsItem < ActiveRecord::Base

  alias_attribute :content, :body
  validates_presence_of :title, :content, :publish_date

  has_friendly_id :title, :use_slug => true

  acts_as_indexed :fields => [:title, :body]

  default_scope :order => "publish_date DESC"

  # If you're using a named scope that includes a changing variable you need to wrap it in a lambda
  # This avoids the query being cached thus becoming unaffected by changes (i.e. Time.now is constant)
  scope :latest, lambda { |*limit| { :conditions => ["publish_date < ?", Time.now], :limit => (limit.first || 10) } }
  scope :published, lambda { { :conditions => ["publish_date < ?", Time.now] } }

  def not_published? # has the published date not yet arrived?
    publish_date > Time.now
  end

  # for will_paginate
  def self.per_page
    20
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
refinerycms-news-0.9.9.1 app/models/news_item.rb
refinerycms-news-0.9.9 app/models/news_item.rb