osem-fcy/app/models/track.rb

42 lines
919 B
Ruby
Raw Normal View History

2013-01-07 09:04:09 +01:00
class Track < ActiveRecord::Base
2017-01-04 22:27:46 -05:00
include RevisionCount
belongs_to :program
has_many :events, dependent: :nullify
2013-01-07 09:04:09 +01:00
has_paper_trail only: [:name, :description, :color], meta: { conference_id: :conference_id }
2013-01-07 09:04:09 +01:00
before_create :generate_guid
validates :name, presence: true
validates :color, format: /\A#[0-9A-F]{6}\z/
validates :short_name,
presence: true,
format: /\A[a-zA-Z0-9_-]*\z/,
uniqueness: {
scope: :program
}
before_validation :capitalize_color
2013-01-07 09:04:09 +01:00
2017-01-04 22:27:46 -05:00
def conference
program.conference
end
2013-01-07 09:04:09 +01:00
private
def generate_guid
2014-06-23 19:07:50 +03:00
guid = SecureRandom.urlsafe_base64
# begin
# guid = SecureRandom.urlsafe_base64
# end while Person.where(:guid => guid).exists?
2013-01-07 09:04:09 +01:00
self.guid = guid
end
def capitalize_color
self.color = color.upcase if color.present?
end
def conference_id
program.conference_id
end
2014-06-30 17:07:53 +02:00
end