dev_forum
SylorHuang 6 years ago
parent f76fc8d7fe
commit 3c92d07cf3

@ -424,14 +424,18 @@ class ExerciseQuestionsController < ApplicationController
begin begin
choice_d_id = params[:choice_no].to_i # 选项的当前位置 choice_d_id = params[:choice_no].to_i # 选项的当前位置
question_choices = @exercise_question.exercise_choices question_choices = @exercise_question.exercise_choices
delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first delete_answer = question_choices.find_by(choice_position: choice_d_id)
left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) left_choices = question_choices.where("choice_position > ? ",choice_d_id)
if left_choice.present? left_choices.update_all("choice_position = choice_position - 1") if left_choices
left_choice.each do |p| # delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first
p.choice_position -= 1 #
p.save # left_choice = question_choices.left_choice_choose("choice_position",choice_d_id)
end # if left_choice.present?
end # left_choice.each do |p|
# p.choice_position -= 1
# p.save
# end
# end
if delete_answer.destroy if delete_answer.destroy
normal_status(0, "答案删除成功!") normal_status(0, "答案删除成功!")
else else
@ -450,13 +454,15 @@ class ExerciseQuestionsController < ApplicationController
begin begin
question_d_id = @exercise_question.question_number.to_i #问题的当前位置 question_d_id = @exercise_question.question_number.to_i #问题的当前位置
exercise_questions = @exercise.exercise_questions exercise_questions = @exercise.exercise_questions
left_question = exercise_questions.left_question_choose("question_number",question_d_id) left_questions = exercise_questions.where("question_number > ?", question_d_id)
if left_question.present? left_questions.update_all("question_number = question_number - 1") if left_questions
left_question.each do |q| # left_question = exercise_questions.left_question_choose("question_number",question_d_id)
q.question_number -= 1 # if left_question.present?
q.save # left_question.each do |q|
end # q.question_number -= 1
end # q.save
# end
# end
if @exercise_question.destroy if @exercise_question.destroy
normal_status(0, "问题删除成功!") normal_status(0, "问题删除成功!")
else else

@ -156,14 +156,18 @@ class PollQuestionsController < ApplicationController
begin begin
answer_d_id = params[:answer_no].to_i # 答案的当前位置 answer_d_id = params[:answer_no].to_i # 答案的当前位置
poll_answers = @poll_question.poll_answers poll_answers = @poll_question.poll_answers
delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first delete_answer = poll_answers.find_by(answer_position: answer_d_id)
left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) left_answers = poll_answers.where("answer_position > ?",answer_d_id)
if left_answer.present? left_answers.update_all("answer_position = answer_position - 1") if left_answers
left_answer.each do |p|
p.answer_position -= 1 # delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first
p.save # left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id)
end # if left_answer.present?
end # left_answer.each do |p|
# p.answer_position -= 1
# p.save
# end
# end
if delete_answer.destroy if delete_answer.destroy
normal_status(0, "答案删除成功!") normal_status(0, "答案删除成功!")
else else

Loading…
Cancel
Save