From 0433f7c87f551b4544e267b335c571a36bde130a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 14 Jan 2015 15:35:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=BB=BA=E5=8D=95?= =?UTF-8?q?=E9=80=89=E9=A2=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 25 +++++++++++++++++++++++-- app/views/poll/_edit_MC.html.erb | 11 ++++++++--- app/views/poll/_poll_form.html.erb | 4 +++- config/locales/zh.yml | 2 ++ db/schema.rb | 12 ------------ 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index b3fdf5087..99287e2cd 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -1,5 +1,5 @@ class PollController < ApplicationController - before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result] + before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question] before_filter :find_container, :only => [:new,:create, :index] before_filter :is_member_of_course, :only => [:index,:show] before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy] @@ -85,7 +85,28 @@ class PollController < ApplicationController #添加单选题 def create_poll_question - a = 1 + question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] + option = { + :is_necessary => params[:is_necessary] || true, + :question_title => question_title, + :question_type => params[:question_type] || 1 + } + @poll_questions = @poll.poll_questions.new option + if params[:question_answer] + for i in 1..params[:question_answer].count + 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] + question_option = { + :answer_position => i, + :answer_text => params[:question_answer].values[i-1] + } + @poll_questions.poll_answers.new question_option + end + end + if @poll_questions.save + respond_to do |format| + format.js + end + end end private diff --git a/app/views/poll/_edit_MC.html.erb b/app/views/poll/_edit_MC.html.erb index 492126827..bf120a20a 100644 --- a/app/views/poll/_edit_MC.html.erb +++ b/app/views/poll/_edit_MC.html.erb @@ -4,15 +4,20 @@
+