mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-11 14:27:04 +08:00
20 lines
652 B
Ruby
20 lines
652 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Tag < ApplicationRecord
|
|
include SearchableModel
|
|
|
|
auto_strip_attributes :name, :color, nullify: false
|
|
validates :name,
|
|
presence: true,
|
|
length: { maximum: Constants::NAME_MAX_LENGTH }
|
|
validates :color,
|
|
presence: true,
|
|
length: { maximum: Constants::COLOR_MAX_LENGTH }
|
|
|
|
belongs_to :team
|
|
belongs_to :created_by, class_name: 'User', optional: true
|
|
belongs_to :last_modified_by, class_name: 'User', optional: true
|
|
has_many :taggings, dependent: :destroy
|
|
|
|
before_validation -> { self.color = Constants::TAG_COLORS.sample.to_s }, if: -> { color.blank? }
|
|
end
|