|
|
@ -9,12 +9,12 @@ class DiscussesController < ApplicationController
|
|
|
|
# 总数,分页使用
|
|
|
|
# 总数,分页使用
|
|
|
|
if current_user.admin?
|
|
|
|
if current_user.admin?
|
|
|
|
@disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count
|
|
|
|
@disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count
|
|
|
|
@discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type,
|
|
|
|
@discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s,
|
|
|
|
:root_id => nil).includes(:user, :praise_tread).offset(offset)
|
|
|
|
:root_id => nil).includes(:user, :praise_tread).offset(offset)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and
|
|
|
|
disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and
|
|
|
|
(hidden = :hidden or user_id = :user_id)",
|
|
|
|
(hidden = :hidden or user_id = :user_id)",
|
|
|
|
{dis_id: dis_id, dis_type: dis_type, hidden: false, user_id: current_user.id})
|
|
|
|
{dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id})
|
|
|
|
@disscuss_count = disscusses.count
|
|
|
|
@disscuss_count = disscusses.count
|
|
|
|
@discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset)
|
|
|
|
@discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -35,7 +35,7 @@ class DiscussesController < ApplicationController
|
|
|
|
@discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type],
|
|
|
|
@discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type],
|
|
|
|
:content => params[:content].gsub(" \;", "").strip, :user_id => current_user.id,
|
|
|
|
:content => params[:content].gsub(" \;", "").strip, :user_id => current_user.id,
|
|
|
|
:praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id],
|
|
|
|
:praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id],
|
|
|
|
:hidden => current_user.admin?)
|
|
|
|
:hidden => !current_user.admin?) # 管理员回复的能够显示
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
|
uid_logger_error("create discuss failed : #{e.message}")
|
|
|
|
uid_logger_error("create discuss failed : #{e.message}")
|
|
|
|
raise Educoder::TipException.new("评论异常")
|
|
|
|
raise Educoder::TipException.new("评论异常")
|
|
|
|