Generate tournament code if not given

This commit is contained in:
Thor77 2018-11-13 16:53:28 +01:00
parent 244da7a2e6
commit 20fafab009
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
1 changed files with 7 additions and 0 deletions

View File

@ -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