class ModifyKeContentsForMarkdown < ActiveRecord::Migration[5.2] include ActionView::Helpers::SanitizeHelper def change def ke_transform_to_md content sanitize(content, tags: %w(img a span), attributes: %w(src href target style)) .gsub(/^(\n)/, "").gsub(/(\n)+/, "
").gsub(/$(\n)/, "") .gsub(/(\n)+/, "
").gsub("\t", "    ") end # 课程讨论区 MessageDetail.find_each do |m| content = ke_transform_to_md m.content puts("content:#{content}") m.update_column(:content, content) end # 试卷 Exercise.find_each do |e| end # 试卷的标题 ExerciseQuestion.find_each do |eq| question_title = ke_transform_to_md eq.question_title puts("question_title:#{question_title}") eq.update_column(:question_title, question_title) end # 试卷的答案 ExerciseStandardAnswer.find_each do |esa| answer_text = ke_transform_to_md esa.answer_text puts("answer_text: #{answer_text}") esa.update_column(:answer_text, answer_text) end # 问卷的标题 PollQuestion.find_each do |pq| question_title = ke_transform_to_md pq.question_title puts("question_title:#{question_title}") pq.update_column(:question_title, question_title) end # # StudentWork # HomeworkCommon # JournalsForMessage # GraduationTask # GraduationTopic # GraduationWork # GtaskBank # GtopicBank # HomeworkBank # QuestionBank # ExerciseBankQuestion # ExerciseBankStandardAnswer # Memo end end