This commit is contained in:
2025-06-30 23:31:39 +09:00
parent 068d0aed14
commit e20f7fcc17
13 changed files with 140 additions and 75 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
class PostTag < ApplicationRecord
belongs_to :post
belongs_to :tag
belongs_to :tag, counter_cache: :post_count
validates :post_id, presence: true
validates :tag_id, presence: true
+8
View File
@@ -19,4 +19,12 @@ class User < ApplicationRecord
def viewed? post
user_post_views.exists? post_id: post.id
end
def member?
['member', 'admin'].include?(role)
end
def admin?
role == 'admin'
end
end
+15 -3
View File
@@ -8,6 +8,11 @@ class WikiPage < ApplicationRecord
validates :title, presence: true, length: { maximum: 255 }, uniqueness: true
def as_json options = { }
self.sha = nil
super options
end
def sha= val
if val.present?
@sha = val
@@ -18,9 +23,16 @@ class WikiPage < ApplicationRecord
end
vers = @page.versions
idx = vers.find_index { |ver| ver.id == @sha }
@pred = vers[idx + 1]&.id
@succ = idx.positive? ? vers[idx - 1].id : nil
@updated_at = vers[idx].authored_date
if idx
@pred = vers[idx + 1]&.id
@succ = idx.positive? ? vers[idx - 1].id : nil
@updated_at = vers[idx].authored_date
else
@sha = nil
@pred = nil
@succ = nil
@updated_at = nil
end
@sha
end