Files
Dena/app/models/concerns/tid_identifiable.rb
2026-08-13 19:50:53 +03:30

18 lines
380 B
Ruby

# encoding: UTF-8
# frozen_string_literal: true
module TIDIdentifiable
extend ActiveSupport::Concern
included do
validates :tid, presence: true, uniqueness: { case_sensitive: false }
before_validation do
next unless tid.blank?
begin
self.tid = "TID#{SecureRandom.hex(5).upcase}"
end while self.class.where(tid: tid).any?
end
end
end