diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 3ca836773..2693eea82 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -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 diff --git a/app/views/student_work/index.html.erb b/app/views/student_work/index.html.erb index 6325abc09..38fcb78c9 100644 --- a/app/views/student_work/index.html.erb +++ b/app/views/student_work/index.html.erb @@ -36,7 +36,7 @@ <% if @show_all%> 搜索 - <%= link_to "缺评情况",student_work_absence_penalty_student_work_index_path(:homework => @homework.id), :class => "student_work_search fl", :target => "_blank" if @is_teacher%> + <%= link_to "缺评情况",student_work_absence_penalty_student_work_index_path(:homework => @homework.id), :class => "student_work_search fl", :target => "_blank" if @is_teacher && @homework.homework_type == 1 && @homework.homework_detail_manual.comment_status != 1 %> <% end%> <% if @is_teacher%>