osem-fcy/app/models/track.rb
Ana 0deaf1abc7 Different colors for new tracks, types and levels
Every time a new track, event type or difficulty level is created, the color picker has a different color by default.

Closes https://github.com/openSUSE/osem/issues/1077
2016-07-11 13:46:01 +02:00

18 lines
420 B
Ruby

class Track < ActiveRecord::Base
belongs_to :program
has_many :events, dependent: :nullify
before_create :generate_guid
validates :name, presence: true
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
private
def generate_guid
guid = SecureRandom.urlsafe_base64
# begin
# guid = SecureRandom.urlsafe_base64
# end while Person.where(:guid => guid).exists?
self.guid = guid
end
end