ADD competition some eelated featrue

dev_course
jasder 6 years ago
parent 0cc4f8262c
commit d21c46339b

@ -43,9 +43,15 @@ class MessagesController < ApplicationController
@page_size = params[:page_size] || 10
@current_user = current_user || nil
@messages = @message.children.preload_messages
@messages = @message.children.preload_messages.includes(:message_detail, :praise_treads)
@messages = @messages.ordered(sort: 1) unless @message.parent_id.nil?
@user_course_identity = current_user.course_identity(@message.board.course)
case @user_course_identity
when 5 || 6 || 7
@messages = @messages.visible
end
@messages = @messages.page(@page).per(@page_size)
end

@ -18,7 +18,7 @@ class Message < ApplicationRecord
scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子
scope :reply_nodes, -> { where("parent_id IS NOT NULL") }
scope :visible, -> { where(is_hidden: false)}
scope :visible, -> { where(is_hidden: false) }
scope :by_user, ->(user) { visible if user.nil? || !user.admin? }
scope :preload_messages, -> { includes(:author, :message_detail) }
scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) }

@ -1,6 +1,6 @@
json.partial! "commons/success"
json.data do
json.user_course_identity @current_user.course_identity(@message.board.course)
json.user_course_identity @user_course_identity
json.id @message.id
json.total_count @messages.total_count
json.total_replies_count @message.total_replies_count

Loading…
Cancel
Save