From 6e88b1adbb584e583f2668423f481abfcfdedaf9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:58:24 +0800 Subject: [PATCH] fix but --- app/controllers/poll_questions_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index dfff147c4..74c73968c 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -200,19 +200,21 @@ class PollQuestionsController < ApplicationController if @poll.polls_status.to_i == 1 if opr.present? if opr.to_s == "up" - last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 + last_q_p = @poll.poll_questions.find_by(question_number: (current_q_p-1)) #当前问题的前一个问题 if last_q_p.present? - last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 @poll_question.update_attribute("question_number", (current_q_p - 1)) + last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 + normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") end elsif opr.to_s == "down" - next_q_p = @poll.poll_questions.next_poll(current_q_p) #当前问题的后一个问题 + next_q_p = @poll.poll_questions.find_by(question_number: (current_q_p+1)) #当前问题的后一个问题 if next_q_p.present? - next_q_p.update_attribute("question_number", current_q_p) @poll_question.update_attribute("question_number", (current_q_p + 1)) + next_q_p.update_attribute("question_number", current_q_p) + normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!")