diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 75c158435..2bc8612a4 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -146,7 +146,13 @@ class ExerciseController < ApplicationController if @exercise_questions.save standart_answer = ExerciseStandardAnswer.new standart_answer.exercise_question_id = @exercise_questions.id - @exercise_questions.question_type == 3 ? standart_answer.answer_text = translate_standard_answer(params[:exercise_choice]) : standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) + if @exercise_questions.question_type == 1 + standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) + elsif @exercise_questions.question_type == 2 + standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) + else + standart_answer.answer_text = sigle_selection_standard_answer(params[:exercise_choice]) + end standart_answer.save respond_to do |format| format.js diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 4cafa8e62..c1bf07407 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -4,7 +4,7 @@ module ExerciseHelper # 单选 def sigle_selection_standard_answer(params) size = params.ord - 96 - if size > 0 + if size > 0 # 小写字母答案 answer = params.ord - 96 else answer = params.ord - 64 @@ -13,7 +13,18 @@ module ExerciseHelper # 多选 def multiselect_standard_answer(params) - answer = params.ord + size = params.ord - 96 + answer = "" + if size > 0 # 小写字母答案 + for i in 0..(params.length-1) + answer += (params[i].ord - 96).to_s + end + else + for i in 0..(params.length-1) + answer += (params[i].ord - 64).to_s + end + end + answer.to_i end #判断用户是否已经提交了问卷