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