From 3fab26214f9912f3f331a9a537e3b3fd2be0f041 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 15 Jan 2015 17:15:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8D=95=E9=80=89=E9=A2=98?= =?UTF-8?q?=E5=90=8E=E9=A1=B5=E9=9D=A2=E6=95=B0=E6=8D=AE=E7=9A=84=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4=E9=A2=98?= =?UTF-8?q?=E7=9B=AE=E7=9A=84=E8=B7=AF=E7=94=B1=E5=8F=8A=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 15 +++++++++++++++ app/views/poll/_show_MC.html.erb | 3 ++- app/views/poll/delete_poll_question.js.erb | 1 + config/routes.rb | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/views/poll/delete_poll_question.js.erb diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 2f8a26c2a..191968183 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -117,6 +117,21 @@ class PollController < ApplicationController a = 1 end + #删除单选题 + def delete_poll_question + @poll_question = PollQuestion.find params[:poll_question] + poll_questions = @poll_question.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 + private def find_poll_and_course @poll = Poll.find params[:id] diff --git a/app/views/poll/_show_MC.html.erb b/app/views/poll/_show_MC.html.erb index 93077b5b3..f3fc9c8b5 100644 --- a/app/views/poll/_show_MC.html.erb +++ b/app/views/poll/_show_MC.html.erb @@ -9,7 +9,8 @@ <%end%> - + <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), + method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %>
diff --git a/app/views/poll/delete_poll_question.js.erb b/app/views/poll/delete_poll_question.js.erb new file mode 100644 index 000000000..ad8fe7674 --- /dev/null +++ b/app/views/poll/delete_poll_question.js.erb @@ -0,0 +1 @@ +$("#poll_questions_<%= @poll_question.id%>").remove(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5a533894c..14f23b5f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,6 +64,9 @@ RedmineApp::Application.routes.draw do post 'create_poll_question' post 'update_poll_question' end + collection do + delete 'delete_poll_question' + end end resources :contest_notification