新建问答题

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
if @exercise_questions.save
# 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])
elsif @exercise_questions.question_type == 2
standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice])
# 问答题标准答案有三个,单独处理
if @exercise_questions.question_type == 3
for i in 1..params[:exercise_choice].count
standart_answer = ExerciseStandardAnswer.new
standart_answer.exercise_question_id = @exercise_questions.id
standart_answer.answer_text = params[:exercise_choice].values[i-1]
standart_answer.save
end
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
standart_answer.save
respond_to do |format|
format.js
end
@ -178,16 +186,17 @@ class ExerciseController < ApplicationController
# params[:question_answer] eg:A、B、C选项
def update_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]
@exercise_question.exercise_answers.each do |answer|
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
end
# @exercise_question.exercise_choices.each do |answer|
# answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
# end
# 界面需要判断选择题至少有一个选项
for i in 1..params[:question_answer].count
question = @exercise_question.exercise_answers.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]
for i in 1..@exercise_question.exercise_choices.count
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]
if question
question.exercise_choices_id = i
question.answer_text = answer

View File

@ -27,8 +27,11 @@ module ExerciseHelper
answer.to_i
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
#判断用户是否已经提交了问卷