Generate tournament code if not given
This commit is contained in:
parent
244da7a2e6
commit
20fafab009
|
|
@ -1,8 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'securerandom'
|
||||
|
||||
class Tournament < ApplicationRecord
|
||||
validates :name, presence: true
|
||||
validates :code, presence: true, uniqueness: true
|
||||
|
||||
has_many :teams, dependent: :destroy
|
||||
belongs_to :user
|
||||
|
||||
after_initialize do |tournament|
|
||||
tournament.code ||= SecureRandom.hex 3
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue