This commit is contained in:
2026-04-05 21:00:13 +09:00
parent f576373c8f
commit 64e7400ed0
14 changed files with 576 additions and 85 deletions
+9 -1
View File
@@ -12,9 +12,17 @@ class Material < ApplicationRecord
has_one_attached :file, dependent: :purge
validates :tag_id, presence: true, uniqueness: true
validate :file_must_be_attached
validate :tag_must_be_material_category
def content_type
return nil unless file&.attached?
file.blob.content_type
end
private
def file_must_be_attached
@@ -24,7 +32,7 @@ class Material < ApplicationRecord
end
def tag_must_be_material_category
return if tag.blank? || tag.material?
return if tag.blank? || tag.character? || tag.material?
errors.add(:tag, '素材カテゴリのタグを指定してください.')
end
+1
View File
@@ -31,6 +31,7 @@ class Tag < ApplicationRecord
class_name: 'TagSimilarity', foreign_key: :target_tag_id, dependent: :delete_all
has_many :deerjikists, dependent: :delete_all
has_many :materials
belongs_to :tag_name
delegate :wiki_page, to: :tag_name