#2 ぼちぼち

This commit is contained in:
2025-02-27 23:38:45 +09:00
parent c6deba7c26
commit 137c86bba7
18 changed files with 156 additions and 31 deletions
+6
View File
@@ -0,0 +1,6 @@
class IpAddress < ApplicationRecord
validates :ip_address, presence: true, length: { maximum: 16 }
validates :banned, inclusion: { in: [true, false] }
has_many :users
end
+17
View File
@@ -0,0 +1,17 @@
class NicoTagRelation < ApplicationRecord
belongs_to :nico_tag, class_name: 'Tag', foreign_key: 'nico_tag_id'
belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id'
validates :nico_tag_id, presence: true
validates :tag_id, prosence: true
validate :nico_tag_must_be_nico
private
def nico_tag_must_be_nico
if nico_tag && nico_tag.category != :nico
errors.add :nico_tag_id, 'タグのカテゴリがニコニコである必要があります.'
end
end
end
+2
View File
@@ -1,2 +1,4 @@
class Post < ApplicationRecord
belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id'
belongs_to :user, foreign_key: ''
end
+14
View File
@@ -0,0 +1,14 @@
class Tag < ApplicationRecord
validates :name, presence: true, length: { maximum: 255 }
validates :category, presence: true, inclusion: { in: categories.keys }
enum category: { deerjikist: 'deerjikist',
meme: 'meme',
character: 'character',
general: 'general',
material: 'material',
nico: 'nico',
meta: 'meta' }
scope :nico_tags, -> { where(category: :nico) }
end
+12
View File
@@ -0,0 +1,12 @@
class User < ApplicationRecord
validates :name, length: { maximum: 255 }
validates :inheritance_code, presence: true, length: { maximum: 64 }
validates :role, presence: true, inclusion: { in: roles.keys }
validates :banned, inclusion: { in: [true, false] }
enum role: { guest: 'guest', member: 'member', admin: 'admin' }
has_many :posts
has_many :settings
has_many :ip_addresses
end