Skip to content

Instantly share code, notes, and snippets.

@alexvbush
Last active August 29, 2015 14:03
Show Gist options
  • Save alexvbush/e7d1d118beb97c4444ee to your computer and use it in GitHub Desktop.
Save alexvbush/e7d1d118beb97c4444ee to your computer and use it in GitHub Desktop.
Second iteration of Article model.
class Article < ActiveRecord::Base
include Categorizable
APPROVED = 'approved'
PENDING = 'pending'
REJECTED = 'rejected'
attr_accessible :approved_at, :url, :body, :image, :rating, :state, :title, :news_source_id, :published_at
validates :url, :uniqueness => true
validates :rating, :inclusion => { :in => (0..10) }
validates :title, :presence => true
mount_uploader :image, PhotoUploader
belongs_to :news_source
def self.pending
where(state: PENDING).order(:published_at)
end
def self.approved
where(state: APPROVED).order('approved_at DESC')
end
#####
# ...
# The rest of the methods ommited
# ...
#####
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment