From 45d5972a93d98b576c57a8a78ed82a283949ccad Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 28 Jul 2015 10:27:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=8F=91=E5=B8=83=E9=97=AE=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E4=B8=AD=E9=97=B4=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 16 +- app/views/poll/_new_MC.html.erb | 1 + app/views/poll/_poll_form.html.erb | 186 ++++++++++++++++++++- app/views/poll/_show_MC.html.erb | 18 +- app/views/poll/_show_MCQ.html.erb | 14 +- app/views/poll/_show_mulit.html.erb | 14 +- app/views/poll/_show_single.html.erb | 14 +- app/views/poll/create_poll_question.js.erb | 6 +- public/stylesheets/polls.css | 5 +- 9 files changed, 261 insertions(+), 13 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 758747e02..8f81bc2c6 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -137,11 +137,19 @@ class PollController < ApplicationController @poll_questions.poll_answers.new question_option end end - if @poll_questions.save - respond_to do |format| - format.js - end + # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 + if params[:quest_id] + @is_insert = true + @poll.poll_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1") + @poll_question_num = params[:quest_num].to_i + @poll_questions.question_number = params[:quest_num].to_i + 1 end + if @poll_questions.save + respond_to do |format| + format.js + end + end + end #修改题目 diff --git a/app/views/poll/_new_MC.html.erb b/app/views/poll/_new_MC.html.erb index 8c47baa01..e5f2a6b82 100644 --- a/app/views/poll/_new_MC.html.erb +++ b/app/views/poll/_new_MC.html.erb @@ -1,5 +1,6 @@ <%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> + <% insert_begin = insert_begin %>