Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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