osem-fcy/app/models/track.rb
Ana 8d9bb56f06 Hexadecimal color changed to capital letters
The default colors in event_types and difficulty levels are in capital letters and the ones that comes from the color picker were not. Now colors are capitalized before saving the track, level or type. A rake task has also been created to capitalize color from old tracks, levels or types.
2016-07-11 13:46:02 +02:00

24 lines
534 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-F]{6}\z/
before_validation :capitalize_color
private
def generate_guid
guid = SecureRandom.urlsafe_base64
# begin
# guid = SecureRandom.urlsafe_base64
# end while Person.where(:guid => guid).exists?
self.guid = guid
end
def capitalize_color
self.color = color.upcase if color.present?
end
end