Last active
August 29, 2015 14:03
-
-
Save alexvbush/e7d1d118beb97c4444ee to your computer and use it in GitHub Desktop.
Second iteration of Article model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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