From 5d506458df259bb9e8ba07fdfb207d1a60eba914 Mon Sep 17 00:00:00 2001 From: huang Date: Sun, 24 Apr 2016 11:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=A9=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20160405021915_delete_anonymous_work.rb | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/db/migrate/20160405021915_delete_anonymous_work.rb b/db/migrate/20160405021915_delete_anonymous_work.rb index 1677b248a..9403c4cc4 100644 --- a/db/migrate/20160405021915_delete_anonymous_work.rb +++ b/db/migrate/20160405021915_delete_anonymous_work.rb @@ -1,16 +1,20 @@ class DeleteAnonymousWork < ActiveRecord::Migration def up - student_works = StudentWork.where("homework_common_id = 2882").map{|work| work.id} unless StudentWork.where("homework_common_id = 2882").empty? - student_work_ids = "(" + student_works.join(",") + ")" - student_work_scores = StudentWorksScore.where("student_work_id in #{student_work_ids}") - unless student_work_scores.empty? - student_work_scores.each do |sscore| - student_work = StudentWork.find sscore.student_work_id - student_work.student_score = 0 unless student_work.nil? - student_work.absence_penalty = 0 - sscore.destroy - student_work.save + begin + student_works = StudentWork.where("homework_common_id = 2882").map{|work| work.id} unless StudentWork.where("homework_common_id = 2882").empty? + student_work_ids = "(" + student_works.join(",") + ")" + student_work_scores = StudentWorksScore.where("student_work_id in #{student_work_ids}") + unless student_work_scores.empty? + student_work_scores.each do |sscore| + student_work = StudentWork.find sscore.student_work_id + student_work.student_score = 0 unless student_work.nil? + student_work.absence_penalty = 0 + sscore.destroy + student_work.save + end end + rescue => e + logger.error "[Errno::ENOENT] ===> #{e}" end end