diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index e6e0ec087..8ae20972c 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -610,15 +610,33 @@ class AdminController < ApplicationController tStart = @page*30 @code_work_tests = CodeTests.find_by_sql("select * from code_tests order by id desc limit #{tStart},30 ") - #取出各个作业是否是模拟答题的 + #取出各个作品是否是模拟答题的 is_test = {} + #作品是否存在 + link_swork = {} + #作业是否存在 + link_hwork = {} @code_work_tests.each do |test| + #作品是否存在 if is_test[test['student_work_id']] != nil + test['link_swork'] = link_swork[test['student_work_id']] test['is_test'] = is_test[test['student_work_id']] else - test['is_test'] = StudentWork.find(test['student_work_id']).is_test + work = StudentWork.where("id=?",test['student_work_id']).first + test['link_swork'] = !work.nil? + test['is_test'] = work.nil? ? false : work.is_test #test['is_test'] = CodeTests.find_by_sql("select is_test from student_works where id = #{test['student_work_id']}").first['is_test'] is_test[test['student_work_id']] = test['is_test'] + link_swork[test['student_work_id']] = test['link_swork'] + end + + #作业是否存在 + if link_hwork[test['homework_id']] != nil + test['link_hwork'] = link_hwork[test['homework_id']] + else + hwork = HomeworkCommon.where("id=?",test['homework_id']).first + test['link_hwork'] = !hwork.nil? + link_hwork[test['homework_id']] = test['link_hwork'] end end diff --git a/app/views/admin/code_work_tests.html.erb b/app/views/admin/code_work_tests.html.erb index cb113f1e6..64c3a41e1 100644 --- a/app/views/admin/code_work_tests.html.erb +++ b/app/views/admin/code_work_tests.html.erb @@ -37,13 +37,21 @@ <% if test['homework_id'] != nil %> "> '> - <%=link_to(test['homework_id'], student_work_index_path(:homework => test['homework_id']))%> + <% if test['link_hwork'] %> + <%=link_to(test['homework_id'], student_work_index_path(:homework => test['homework_id']))%> + <% else %> + <%= test['homework_id'] %> + <% end %> '> - <% if !test['is_test'] %> - <%=link_to(test['student_work_id'], student_work_index_path(:homework => test['homework_id'],:student_work_id=>test['student_work_id']))%> + <% if test['link_swork'] && test['link_hwork'] %> + <% if !test['is_test'] %> + <%=link_to(test['student_work_id'], student_work_index_path(:homework => test['homework_id'],:student_work_id=>test['student_work_id']))%> + <% else %> + <%=link_to(test['student_work_id'], new_user_commit_homework_users_path(homework_id: test['homework_id'], is_test: true))%> + <% end %> <% else %> - <%=link_to(test['student_work_id'], new_user_commit_homework_users_path(homework_id: test['homework_id'], is_test: true))%> + <%= test['student_work_id'] %> <% end %>