30 lines
872 B
Ruby
30 lines
872 B
Ruby
class JamRuby::EventSession < ActiveRecord::Base
|
|
|
|
attr_accessible :event_id, :user_id, :band_id, :starts_at, :ends_at, :pinned_state, :position, :img_url, :img_width, :img_height, as: :admin
|
|
|
|
belongs_to :user, class_name: 'JamRuby::User'
|
|
belongs_to :band, class_name: 'JamRuby::Band'
|
|
belongs_to :event
|
|
|
|
|
|
validates :event, presence: true
|
|
validates :pinned_state, :inclusion => {:in => [nil, 'not_started', 'over']}
|
|
validate :one_of_user_band
|
|
|
|
before_validation :sanitize_active_admin
|
|
|
|
def sanitize_active_admin
|
|
puts self.inspect
|
|
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.pinned_state = nil if self.pinned_state == ''
|
|
end
|
|
|
|
def one_of_user_band
|
|
if band && user
|
|
errors.add(:user, 'specify band, or user. not both')
|
|
end
|
|
end
|
|
end
|