From a0a5f3410847752d2c28c535a801976558046546 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 29 Jul 2015 10:07:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E4=BB=A5=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 31 +++++++++++++++++++++ app/views/poll/_poll_form.html.erb | 43 +++++++++++++++++++++++++++++- app/views/poll/_show_head.html.erb | 3 +++ 3 files changed, 76 insertions(+), 1 deletion(-) 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 @@