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