@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user