Skip to content

Instantly share code, notes, and snippets.

@alexvbush
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexvbush/fefa22f4fc203f47d0c4 to your computer and use it in GitHub Desktop.
Save alexvbush/fefa22f4fc203f47d0c4 to your computer and use it in GitHub Desktop.
First naive implementation 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
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