class Cms::PageWorkflow < ActiveRecord::Base self.table_name = 'cms_page_workflows' belongs_to :page, :foreign_key => 'cms_page_id' after_save do |record| record.page.update_attribute(:is_published, record.page_published?) end def self.statuses { 0 => :draft, 1 => :reviewed, # 2 => :scheduled, 3 => :published } end def self.statuses_for_select(can_publish, can_review) ret = [["Draft", 0]] ret << ["Review", 1] if can_review ret << ["Published", 3] if can_publish # self.statuses.map {|k,v| [v.to_s.titleize, k]} ret end def page_published? (status_id.eql?(3) || status_id.eql?(2)) && published_date <= Date.today end end