|
|
@ -117,6 +117,30 @@ class PollController < ApplicationController
|
|
|
|
@poll_question = PollQuestion.find params[:poll_question]
|
|
|
|
@poll_question = PollQuestion.find params[:poll_question]
|
|
|
|
@poll = @poll_question.poll
|
|
|
|
@poll = @poll_question.poll
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@poll_question.is_necessary = params[:is_necessary]=="true" ? 1 : 0
|
|
|
|
|
|
|
|
@poll_question.question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
|
|
|
|
|
|
|
|
################处理选项
|
|
|
|
|
|
|
|
if params[:question_answer]
|
|
|
|
|
|
|
|
@poll_question.poll_answers.each do |answer|
|
|
|
|
|
|
|
|
@poll_question.poll_answers.destroy answer unless params[:question_answer].keys.include? answer.id.to_s
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
for i in 1..params[:question_answer].count
|
|
|
|
|
|
|
|
question = @poll_question.poll_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]
|
|
|
|
|
|
|
|
if question
|
|
|
|
|
|
|
|
question.answer_position = i
|
|
|
|
|
|
|
|
question.answer_text = answer
|
|
|
|
|
|
|
|
question.save
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
question_option = {
|
|
|
|
|
|
|
|
:answer_position => i,
|
|
|
|
|
|
|
|
:answer_text => answer
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@poll_question.poll_answers.new question_option
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
@poll_question.save
|
|
|
|
respond_to do |format|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|