From a9aa1ec83800914d9e93e863b59b66f95c0dda9e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 22 Jul 2019 14:58:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=8F=82=E8=80=83=E7=AD=94?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190722062800_modify_answer_for_challenges.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 db/migrate/20190722062800_modify_answer_for_challenges.rb diff --git a/db/migrate/20190722062800_modify_answer_for_challenges.rb b/db/migrate/20190722062800_modify_answer_for_challenges.rb new file mode 100644 index 000000000..747564d68 --- /dev/null +++ b/db/migrate/20190722062800_modify_answer_for_challenges.rb @@ -0,0 +1,11 @@ +class ModifyAnswerForChallenges < ActiveRecord::Migration[5.2] + def change + challenges = Challenge.where("answer is not null or answer != ''") + .includes(:challenge_answers).unscoped + challenges.find_each do |c| + next if c.challenge_answers.present? + puts("############challenge_id:##{c.id}") + ChallengeAnswer.create(name: "解题代码", contents: "#{c.answer}", level: 1, score: 100, challenge_id: c.id) + end + end +end