diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index cec9b3a34..feeb3c324 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -60,12 +60,14 @@ class PollController < ApplicationController end def update - @poll.polls_name = params[:polls_name] + @poll.polls_name = params[:polls_name].empty? ? l(:label_poll_title) : params[:polls_name] + @poll.polls_description = params[:polls_description].empty? ? l(:label_poll_description) : params[:polls_description] if @poll.save respond_to do |format| - format.html { redirect_to poll_index_url(:polls_type => @course.class.to_s, :polls_group_id => @course.id) } + format.js end else + render_404 end end @@ -87,7 +89,7 @@ class PollController < ApplicationController def create_poll_question 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, + :is_necessary => (params[:is_necessary]=="true" ? 1 : 0), :question_title => question_title, :question_type => params[:question_type] || 1, :question_number => @poll.poll_questions.count + 1 @@ -98,7 +100,7 @@ class PollController < ApplicationController 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] + :answer_text => answer } @poll_questions.poll_answers.new question_option end @@ -110,6 +112,32 @@ class PollController < ApplicationController end end + #修改单选题 + def update_poll_question + @poll_question = PollQuestion.find params[:poll_question] + @poll = @poll_question.poll + + respond_to do |format| + format.js + end + end + + #删除单选题 + def delete_poll_question + @poll_question = PollQuestion.find params[:poll_question] + @poll = @poll_question.poll + poll_questions = @poll.poll_questions.where("question_number > #{@poll_question.question_number}") + poll_questions.each do |question| + question.question_number -= 1 + question.save + end + if @poll_question && @poll_question.destroy + respond_to do |format| + format.js + end + end + end + #提交答案 def commit_answer pq = PollQuestion.find(params[:poll_question_id]) diff --git a/app/views/poll/_edit_MC.html.erb b/app/views/poll/_edit_MC.html.erb index 0f031f61c..fa0e8d802 100644 --- a/app/views/poll/_edit_MC.html.erb +++ b/app/views/poll/_edit_MC.html.erb @@ -1,45 +1,31 @@ -<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> -