From cd2d947cb2c74c57605ad483e43a71595f0f282e Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 Nov 2015 16:06:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E9=A1=B9=E9=80=89=E6=8B=A9=E6=A0=87?= =?UTF-8?q?=E5=87=86=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 8 +++++++- app/helpers/exercise_helper.rb | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) 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 2c92ffad7..d4caf00b5 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 #判断用户是否已经提交了问卷