Last active
August 29, 2015 14:03
-
-
Save alexvbush/fefa22f4fc203f47d0c4 to your computer and use it in GitHub Desktop.
First naive implementation 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 | |
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 | |
end | |
def self.approved | |
where state: APPROVED | |
end | |
def approve | |
self.state = APPROVED | |
self.approved_at = DateTime.now | |
end | |
def reject | |
self.state = REJECTED | |
self.approved_at = nil | |
end | |
def enqueue | |
self.state = PENDING | |
self.approved_at = nil | |
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