From ff177557c802c48f33192051d4c73280a2db8f5c Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Wed, 20 Apr 2016 16:13:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=88=97=E8=A1=A8=E6=8A=A5500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index e581216fe..e6e0ec087 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -600,8 +600,9 @@ class AdminController < ApplicationController #设置个空的数组 以便paginateHelper来分页 @code_work_tests = [] - @code_work_tests[tCount-1] = {} - + if tCount >= 1 + @code_work_tests[tCount-1] = {} + end @code_work_tests = paginateHelper @code_work_tests,30 @page = (params['page'] || 1).to_i - 1 From d538d1967bda900187bab90633027d349d61d340 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 21 Apr 2016 11:16:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=95=8C=E9=9D=A2=E4=BB=A3=E7=A0=81=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=88=97=E8=A1=A8404=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 22 ++++++++++++++++++++-- app/views/admin/code_work_tests.html.erb | 16 ++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) 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 %>