jam-cloud/ruby/lib/jam_ruby/models/promotional.rb

59 lines
1.2 KiB
Ruby

class JamRuby::Promotional < ActiveRecord::Base
self.table_name = :promotionals
self.abstract_class = true
attr_accessible :expires_at, :position, :aasm_state
include AASM
HIDDEN_STATE = :hidden
ACTIVE_STATE = :active
EXPIRED_STATE = :expired
STATES = [HIDDEN_STATE, ACTIVE_STATE, EXPIRED_STATE]
aasm do
state HIDDEN_STATE, :initial => true
state ACTIVE_STATE
state EXPIRED_STATE
event :activate do
transitions :from => [HIDDEN_STATE, EXPIRED_STATE], :to => ACTIVE_STATE
end
event :expire do
transitions :from => [HIDDEN_STATE, ACTIVE_STATE], :to => EXPIRED_STATE
end
event :hide do
transitions :from => [HIDDEN_STATE, ACTIVE_STATE], :to => HIDDEN_STATE
end
end
def state
aasm_state
end
end
class JamRuby::PromoBuzz < JamRuby::Promotional
attr_accessible :original_fpfile_photo, :photo_url, :text_short, :text_long
def self.create_with_params(params)
obj = self.new
obj.text_short = params[:text_short]
obj.text_long = params[:text_long]
obj.save!
obj
end
def admin_title
"Buzz #{created_at.strftime('%Y-%m-%d %H-%M')}"
end
end
class JamRuby::PromoLatest < JamRuby::Promotional
belongs_to :latest, :polymorphic => true
end