みてるぞ 2 months ago
parent
commit
1be97b5afa
3 changed files with 12 additions and 2 deletions
  1. +1
    -1
      backend/app/models/nico_tag_relation.rb
  2. +1
    -1
      backend/app/models/post.rb
  3. +10
    -0
      backend/app/models/tag.rb

+ 1
- 1
backend/app/models/nico_tag_relation.rb View File

@@ -10,7 +10,7 @@ class NicoTagRelation < ApplicationRecord
private private


def nico_tag_must_be_nico def nico_tag_must_be_nico
if nico_tag && nico_tag.category != :nico
if nico_tag && nico_tag.category != 'nico'
errors.add :nico_tag_id, 'タグのカテゴリがニコニコである必要があります.' errors.add :nico_tag_id, 'タグのカテゴリがニコニコである必要があります.'
end end
end end


+ 1
- 1
backend/app/models/post.rb View File

@@ -1,6 +1,6 @@
class Post < ApplicationRecord class Post < ApplicationRecord
belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id' belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id'
belongs_to :user, foreign_key: ''
belongs_to :uploaded_user, class_name: 'User', optional: true
has_many :post_tags, dependent: :destroy has_many :post_tags, dependent: :destroy
has_many :tags, through: :post_tags has_many :tags, through: :post_tags
has_many :user_post_views, dependent: :destroy has_many :user_post_views, dependent: :destroy


+ 10
- 0
backend/app/models/tag.rb View File

@@ -15,5 +15,15 @@ class Tag < ApplicationRecord
validates :name, presence: true, length: { maximum: 255 } validates :name, presence: true, length: { maximum: 255 }
validates :category, presence: true, inclusion: { in: Tag.categories.keys } validates :category, presence: true, inclusion: { in: Tag.categories.keys }


validate :nico_tag_name_must_start_with_nico

scope :nico_tags, -> { where category: :nico } scope :nico_tags, -> { where category: :nico }

private

def nico_tag_name_must_start_with_nico
if category == 'nico' && name&.[](0, 5) != 'nico:'
errors.add :name, 'ニコニコ・タグの命名規則に反してゐます.'
end
end
end end

Loading…
Cancel
Save