删除某一题目后,后面的题目序号自动-1,以及页面js的刷新

This commit is contained in:
sw 2015-01-15 17:26:56 +08:00
parent 3fab26214f
commit 5ec2789881
4 changed files with 14 additions and 12 deletions

View File

@ -120,7 +120,8 @@ class PollController < ApplicationController
#删除单选题
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 = @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

View File

@ -0,0 +1,10 @@
<% poll.poll_questions.each do |poll_question|%>
<div id="poll_questions_<%= poll_question.id%>">
<div id="show_poll_questions_<%= poll_question.id %>">
<%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %>
</div>
<div id="edit_poll_questions_<%= poll_question.id %>" style="display: none;">
<%= render :partial => 'edit_MC', :locals => {:poll_question => poll_question} %>
</div>
</div>
<% end %>

View File

@ -96,16 +96,7 @@
<!-- 问题 -->
<div id="poll_content">
<% @poll.poll_questions.each do |poll_question|%>
<div id="poll_questions_<%= poll_question.id%>">
<div id="show_poll_questions_<%= poll_question.id %>">
<%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %>
</div>
<div id="edit_poll_questions_<%= poll_question.id %>" style="display: none;">
<%= render :partial => 'edit_MC', :locals => {:poll_question => poll_question} %>
</div>
</div>
<% end %>
<%= render :partial => 'poll_content', :locals => {:poll => @poll}%>
</div>
<!-- 新增问题 -->

View File

@ -1 +1 @@
$("#poll_questions_<%= @poll_question.id%>").remove();
$("#poll_content").html("<%= escape_javascript(render :partial => 'poll_content', :locals => {:poll => @poll}) %>");