diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 8f81bc2c6..dda5b81b2 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -336,6 +336,37 @@ class PollController < ApplicationController end end + + def import_poll + @poll = Poll.find(params[:to_id]) + question_num = @poll.poll_questions.select("max(question_number) question_number").first.question_number + import_poll = Poll.find(params[:import_id]) + import_poll.poll_questions.each_with_index do |question,index| + option = { + :is_necessary => question.is_necessary, + :question_title => question.question_title, + :question_type => question.question_type, + :question_number => question_num + index+1 + } + poll_questions = @poll.poll_questions.new option + for i in 1..question.poll_answers.count + answer = question.poll_answers[i-1][:answer_text] + question_option = { + :answer_position => i, + :answer_text => answer + } + poll_questions.poll_answers.new question_option + end + @poll.poll_questions << poll_questions + end + if @poll.save + @poll = Poll.find(params[:to_id]) + respond_to do |format| + format.js + end + end + end + #重新发布问卷 def republish_poll @poll.poll_questions.each do |poll_question| diff --git a/app/views/poll/_poll_form.html.erb b/app/views/poll/_poll_form.html.erb index d784edab3..c5c016583 100644 --- a/app/views/poll/_poll_form.html.erb +++ b/app/views/poll/_poll_form.html.erb @@ -3,6 +3,7 @@