去除评分时部分重复查询

dev_chuangbin
sw 11 years ago
parent 7a727bfed7
commit 3dc7c55aef

@ -435,6 +435,7 @@ class HomeworkAttachController < ApplicationController
@is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value]
@cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5
@homework = HomeworkAttach.find(params[:homework_id])
@stars_reates = @homework.rates(:quality)
homework = @homework
is_teacher = @is_teacher ? 1 : 0
#保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0))
@ -446,12 +447,13 @@ class HomeworkAttachController < ApplicationController
else
@homework.rates(:quality).new(:stars => @m_score, :rater_id => User.current.id, :is_teacher_score => is_teacher).save!
end
if homework.is_teacher_score == 0
if is_teacher == 1
homework.score = @m_score
homework.is_teacher_score = 1
else
homework.score = homework.rates(:quality).select("avg(stars)")
homework.score = @stars_reates.select("avg(stars)")
end
else
if is_teacher == 1
@ -468,7 +470,6 @@ class HomeworkAttachController < ApplicationController
@homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation
end
@stars_reates = @homework.rates(:quality)
@teacher_stars = @stars_reates.where("is_teacher_score = 1") #老师评分列表
@student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据

Loading…
Cancel
Save