新建问答题

This commit is contained in:
huang 2015-11-18 19:58:00 +08:00
parent 8e4b2bd7d4
commit 8cf22767f9
2 changed files with 29 additions and 17 deletions

View File

@ -156,16 +156,24 @@ class ExerciseController < ApplicationController
end end
if @exercise_questions.save if @exercise_questions.save
# params[:exercise_choice] 标准答案参数 # params[:exercise_choice] 标准答案参数
standart_answer = ExerciseStandardAnswer.new # 问答题标准答案有三个,单独处理
standart_answer.exercise_question_id = @exercise_questions.id if @exercise_questions.question_type == 3
if @exercise_questions.question_type == 1 for i in 1..params[:exercise_choice].count
standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) standart_answer = ExerciseStandardAnswer.new
elsif @exercise_questions.question_type == 2 standart_answer.exercise_question_id = @exercise_questions.id
standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) standart_answer.answer_text = params[:exercise_choice].values[i-1]
standart_answer.save
end
else else
standart_answer.answer_text = fill_standart_answer(params[:exercise_choice]) standart_answer = ExerciseStandardAnswer.new
standart_answer.exercise_question_id = @exercise_questions.id
if @exercise_questions.question_type == 1
standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice])
else
standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice])
end
standart_answer.save
end end
standart_answer.save
respond_to do |format| respond_to do |format|
format.js format.js
end end
@ -178,16 +186,17 @@ class ExerciseController < ApplicationController
# params[:question_answer] eg:A、B、C选项 # params[:question_answer] eg:A、B、C选项
def update_exercise_question def update_exercise_question
@exercise_question = ExerciseQuestion.find params[:exercise_question] @exercise_question = ExerciseQuestion.find params[:exercise_question]
@exercise_question.question_title = params[:exercise_questions_title].nil? || params[:exercise_questions_title].empty? ? l(:label_enter_single_title) : params[:exercise_questions_title] @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
@exercise_question.question_score = params[:question_score]
################处理选项 ################处理选项
if params[:question_answer] if params[:question_answer]
@exercise_question.exercise_answers.each do |answer| # @exercise_question.exercise_choices.each do |answer|
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s # answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
end # end
# 界面需要判断选择题至少有一个选项 # 界面需要判断选择题至少有一个选项
for i in 1..params[:question_answer].count for i in 1..@exercise_question.exercise_choices.count
question = @exercise_question.exercise_answers.find_by_id params[:question_answer].keys[i-1] question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1]
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] # answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
if question if question
question.exercise_choices_id = i question.exercise_choices_id = i
question.answer_text = answer question.answer_text = answer

View File

@ -27,8 +27,11 @@ module ExerciseHelper
answer.to_i answer.to_i
end end
def fill_standart_answer(params) def fill_standart_answer(params, standart_answer)
params.each do |param|
standart_answer.answer_text = param.value
standart_answer.save
end
end end
#判断用户是否已经提交了问卷 #判断用户是否已经提交了问卷