class JamRuby::LiveStream < ActiveRecord::Base attr_accessible :user_id, :band_id, :starts_at, :ends_at, :img_url, :slug, :title, :description, :listed, :allow_in, :white_label_player, :youtube_code, :eventbriteid, :event_type, :social_description, :event_brite_registration_url, as: :admin #belongs_to :user, class_name: 'JamRuby::User' #belongs_to :band, class_name: 'JamRuby::Band' #validate :one_of_user_band validates :slug, uniqueness: true, presence: true before_validation :sanitize_active_admin def ready_display self.starts_at && self.ends_at && (self.user_id || self.band_id) end def self.upcoming LiveStream.where(listed: true).order('starts_at DESC') #.where("starts_at > ?", 2.days.ago) end def sanitize_active_admin self.img_url = nil if self.img_url == '' self.user_id = nil if self.user_id == '' self.band_id = nil if self.band_id == '' self.social_description = nil if self.social_description == '' end def one_of_user_band if band && user errors.add(:user, 'specify band, or user. not both') end end def admin_name "#{title} EB:#{eventbriteid} #{starts_at}" end end