diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 411fa1b29..6046be5af 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -240,7 +240,7 @@ class ApplicationController < ActionController::Base uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) if !User.current.logged? && Rails.env.development? - # User.current = User.find 1 + User.current = User.find 1 end diff --git a/app/controllers/poll_bank_questions_controller.rb b/app/controllers/poll_bank_questions_controller.rb index f1d5c6e2c..19111f4ca 100644 --- a/app/controllers/poll_bank_questions_controller.rb +++ b/app/controllers/poll_bank_questions_controller.rb @@ -74,7 +74,7 @@ class PollBankQuestionsController < ApplicationController end end (1..p_answer_count).each do |i| - answer = @poll_question.exercise_bank_choices.find_by_custom("choice_position",i).first + answer = @poll_question.exercise_bank_choices.find_choice_custom("choice_position",i).first if answer # 判断该位置的answer是否存在,存在则更新.不存在则跳到下一步 answer.choice_text = p_answer[i-1] answer.choice_position = i @@ -88,7 +88,7 @@ class PollBankQuestionsController < ApplicationController end end if p_other_answer #判断答案的其他选项是否存在 - other_answer = @poll_question.exercise_bank_choices.find_by_custom("choice_text","").first + other_answer = @poll_question.exercise_bank_choices.find_choice_custom("choice_text","").first if other_answer.blank? question_option = { :choice_position => p_answer_count + 1, @@ -131,26 +131,26 @@ class PollBankQuestionsController < ApplicationController end def validates_params - normal_status(-1, "问题标题不能为空!") if params[:question_title].blank? - normal_status(-1, "是否要求必答的值不能为空!") if params[:is_necessary].blank? - normal_status(-1, "问题类型不能为空!") if params[:question_type].blank? + tip_exception(-1, "问题标题不能为空!") if params[:question_title].blank? + tip_exception(-1, "是否要求必答的值不能为空!") if params[:is_necessary].blank? + tip_exception(-1, "问题类型不能为空!") if params[:question_type].blank? if params[:min_choices].present? && params[:max_choices].present? && (params[:min_choices].to_i > params[:max_choices].to_i) - normal_status(-1, "最小可选不能大于最大可选!") + tip_exception(-1, "最小可选不能大于最大可选!") elsif params[:question_answers].present? && (params[:max_choices].to_i > params[:question_answers].count) - normal_status(-1, "选择题的最大可选项不能大于答案数!") + tip_exception(-1, "选择题的最大可选项不能大于答案数!") elsif [1,3].include?(params[:question_type]) && (params[:max_choices].to_i > 0 || params[:min_choices].to_i > 0) - normal_status(-1, "单选题或主观题不能有最大或最小选择数!") + tip_exception(-1, "单选题或主观题不能有最大或最小选择数!") elsif params[:question_type] == 3 && (params[:question_answers] || params[:question_other_answer]) - normal_status(-1, "主观问题不需要可选答案!") + tip_exception(-1, "主观问题不需要可选答案!") elsif params[:question_type] != 3 if params[:question_answers].present? && params[:question_answers].include?("") - normal_status(-1, "选择题不能有空值!") + tip_exception(-1, "选择题不能有空值!") elsif params[:question_other_answer].present? && params[:question_other_answer].length > 0 - normal_status(-1, "其他选项不能有值!") + tip_exception(-1, "其他选项不能有值!") elsif params[:question_type] == 1 && params[:question_answers].count < 2 - normal_status(-1, "单选题选项不能小于2!") + tip_exception(-1, "单选题选项不能小于2!") elsif params[:question_type] == 2 && params[:question_answers].count < 3 - normal_status(-1, "多选题选项不能小于3!") + tip_exception(-1, "多选题选项不能小于3!") end end end diff --git a/db/migrate/20190831014325_migrate_poll_bank_question.rb b/db/migrate/20190831014325_migrate_poll_bank_question.rb new file mode 100644 index 000000000..cd9168a73 --- /dev/null +++ b/db/migrate/20190831014325_migrate_poll_bank_question.rb @@ -0,0 +1,6 @@ +class MigratePollBankQuestion < ActiveRecord::Migration[5.2] + def change + ExerciseBankQuestion.where(question_type: 0, exercise_bank_id: ExerciseBank.where(container_type: 'Poll').pluck(:id)).update_all(question_type: 1) + ExerciseBankQuestion.where(question_type: 1, exercise_bank_id: ExerciseBank.where(container_type: 'Poll').pluck(:id)).update_all(question_type: 2) + end +end