From 9cf1de1880989b765c9f896b2867eca4a0e4f91d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 8 May 2019 13:00:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...508045744_migrate_exercise_answer_score.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 db/migrate/20190508045744_migrate_exercise_answer_score.rb diff --git a/db/migrate/20190508045744_migrate_exercise_answer_score.rb b/db/migrate/20190508045744_migrate_exercise_answer_score.rb new file mode 100644 index 00000000..3b639d92 --- /dev/null +++ b/db/migrate/20190508045744_migrate_exercise_answer_score.rb @@ -0,0 +1,20 @@ +class MigrateExerciseAnswerScore < ActiveRecord::Migration + def up + exercise = Exercise.where(:id => 1527).first + if exercise.present? + exercise.exercise_users.each do |exercise_user| + score = 0 + exercise.exercise_questions.each do |question| + ExerciseShixunAnswer.where(exercise_question_id: question.id, user_id: exercise_user.user_id).each do |answer| + score += answer.score + end + end + + exercise_user.update_attributes(objective_score: score, score: score) + end + end + end + + def down + end +end