mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Don't use tracks ids in urls Add short_name to tracks and use that in urls as the identifier
36 lines
848 B
Ruby
36 lines
848 B
Ruby
class Track < ActiveRecord::Base
|
|
belongs_to :program
|
|
has_many :events, dependent: :nullify
|
|
|
|
has_paper_trail only: [:name, :description, :color], meta: { conference_id: :conference_id }
|
|
|
|
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
|
|
|
|
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
|
|
|
|
def conference_id
|
|
program.conference_id
|
|
end
|
|
end
|