From b6300cfc846fa030b2823dc6e2a93e69c01b1a67 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:31:37 +0800 Subject: [PATCH 1/5] fix bug --- app/controllers/poll_questions_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 69aef41c0..59af29758 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -197,22 +197,22 @@ class PollQuestionsController < ApplicationController begin opr = params[:opr] current_q_p = @poll_question.question_number.to_i #问题的当前位置 - last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 - next_q_p = @poll.poll_questions.next_poll(current_q_p) # 当前问题的后一个问题 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) #当前问题的前一个问题 if last_q_p.present? - @poll_question.update_attribute(:question_number, (current_q_p - 1)) - last_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i + 1)) # 重新获取当前问题的位置 + @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) #当前问题的后一个问题 if next_q_p.present? - @poll_question.update_attribute(:question_number, (current_q_p + 1)) - next_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i - 1)) + @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, "移动失败,已经是最后一个问题了!") From d0249457473611d77d6a01de9a6b5224248286e0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:41:33 +0800 Subject: [PATCH 2/5] fix bug --- app/controllers/poll_questions_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 59af29758..dfff147c4 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -202,8 +202,8 @@ class PollQuestionsController < ApplicationController if opr.to_s == "up" last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 if last_q_p.present? - @poll_question.update_attribute("question_number", (current_q_p - 1)) last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 + @poll_question.update_attribute("question_number", (current_q_p - 1)) normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") @@ -211,8 +211,8 @@ class PollQuestionsController < ApplicationController elsif opr.to_s == "down" next_q_p = @poll.poll_questions.next_poll(current_q_p) #当前问题的后一个问题 if next_q_p.present? - @poll_question.update_attribute("question_number", (current_q_p + 1)) next_q_p.update_attribute("question_number", current_q_p) + @poll_question.update_attribute("question_number", (current_q_p + 1)) normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!") From d10567926b923bed180ffd519ed40b79a74d4d9f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 26 Jun 2019 14:55:47 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E9=80=89=E9=A2=98?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E9=A2=98=E5=BA=93=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index a6903dbc7..ce4488ffd 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -223,7 +223,7 @@ class GraduationTopicsController < ApplicationController # 已加入的更新,未加入的新建 if topic_bank.present? - topic_bank.update_attributes(name: topic, description: topic.description, + topic_bank.update_attributes(name: topic.name, description: topic.description, topic_source: topic.topic_source, topic_property_first: topic.topic_property_first, topic_property_second: topic.topic_property_second, @@ -234,7 +234,7 @@ class GraduationTopicsController < ApplicationController course_list_id: @course.course_list_id) topic_bank.attachments.destroy_all else - topic_bank = GtopicBank.new(name: topic, description: topic.description, + topic_bank = GtopicBank.new(name: topic.name, description: topic.description, topic_source: topic.topic_source, topic_property_first: topic.topic_property_first, topic_property_second: topic.topic_property_second, From 6e88b1adbb584e583f2668423f481abfcfdedaf9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:58:24 +0800 Subject: [PATCH 4/5] 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, "移动失败,已经是最后一个问题了!") From d9608410f69e0726f31e330f3f2e9af6777557ad Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 15:04:09 +0800 Subject: [PATCH 5/5] fix bug --- app/controllers/exercise_questions_controller.rb | 10 ++++------ app/controllers/poll_questions_controller.rb | 1 - app/models/exercise_question.rb | 4 ++-- app/models/poll_question.rb | 2 -- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 96951ac48..490791918 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -384,24 +384,22 @@ class ExerciseQuestionsController < ApplicationController begin opr = params[:opr] current_q_p = @exercise_question.question_number.to_i #问题的当前位置 - # last_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p - 1)).first # 当前问题的前一个问题 - # next_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p + 1)).first # 当前问题的后一个问题 - last_q_p = @exercise.exercise_questions.last_exercise(current_q_p) # 当前问题的前一个问题 - next_q_p = @exercise.exercise_questions.next_exercise(current_q_p) # 当前问题的后一个问题 if @exercise.exercise_status.to_i == 1 if opr.present? if opr.to_s == "up" + last_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题 if last_q_p.present? @exercise_question.update_attribute('question_number', (current_q_p - 1)) - last_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i + 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 = @exercise.exercise_questions.find_by(question_number: (current_q_p + 1)) # 当前问题的前一个问题 if next_q_p.present? @exercise_question.update_attribute('question_number', (current_q_p + 1)) - next_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i - 1)) + next_q_p.update_attribute('question_number', current_q_p) normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!") diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 74c73968c..47cd236a9 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -204,7 +204,6 @@ class PollQuestionsController < ApplicationController if last_q_p.present? @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, "移动失败,已经是第一个问题了!") diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index ae58a7592..5f456e21f 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -15,8 +15,8 @@ class ExerciseQuestion < ApplicationRecord scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 - scope :next_exercise, lambda {|k| where("question_number > ?",k).first} - scope :last_exercise, lambda {|k| where("question_number < ?",k).last} + # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} + # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} def question_type_name case self.question_type diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index 958b69acd..1fc8e0c16 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -8,8 +8,6 @@ class PollQuestion < ApplicationRecord scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_necessary, -> {where("is_necessary = ?",1)} scope :insert_question, lambda {|k| where("question_number > ?",k)} - scope :next_poll, lambda {|k| where("question_number > ?",k).first} - scope :last_poll, lambda {|k| where("question_number < ?",k).last} def question_type_name case self.question_type