作品列表为空时缺评列表报错

This commit is contained in:
sw 2015-06-19 16:23:28 +08:00
parent 95ab6dd6c0
commit a9ff9f96bd
1 changed files with 8 additions and 4 deletions

View File

@ -245,15 +245,19 @@ class StudentWorkController < ApplicationController
def student_work_absence_penalty
render_403 unless User.current.allowed_to?(:as_teacher,@course)
order = params[:order] || "desc"
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
@stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM(
if @homework.student_works.empty?
@stundet_works = []
else
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
@stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM(
SELECT * ,
(SELECT COUNT(*) FROM `student_works_evaluation_distributions` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS all_count,
(SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count
FROM `student_works`
WHERE homework_common_id = #{@homework.id}
) AS table_1
ORDER BY absence #{order}")
) AS table_1
ORDER BY absence #{order}")
end
@order = order == "desc" ? "asc" : "desc"
respond_to do |format|
format.html