diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index e73243b94..762943183 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -287,21 +287,34 @@ class ChallengesController < ApplicationController def index_down next_challenge = @challenge.next_challenge position = @challenge.position - @challenge.update_attribute(:position, (position + 1)) - next_challenge.update_attribute(:position, next_challenge.position - 1) - # 关卡位置被修改,需要修改脚本 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) + begin + ActiveRecord::Base.transaction do + @challenge.update_attributes!(position: (position + 1)) + next_challenge.update_attributes!(position: next_challenge.position - 1) + # 关卡位置被修改,需要修改脚本 + script = modify_shixun_script @shixun, @shixun.evaluate_script + @shixun.shixun_info.update_attributes!(evaluate_script: script) + end + rescue => e + tip_exception("下移失败: #{e.message}") + end end def index_up position = @challenge.position last_challenge = @challenge.last_challenge - @challenge.update_attribute(:position, (position - 1)) - last_challenge.update_attribute(:position, last_challenge.position + 1) - # 关卡位置被修改,需要修改脚本 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) + begin + ActiveRecord::Base.transaction do + @challenge.update_attribute(:position, (position - 1)) + last_challenge.update_attribute(:position, last_challenge.position + 1) + # 关卡位置被修改,需要修改脚本 + script = modify_shixun_script @shixun, @shixun.evaluate_script + @shixun.shixun_info.update_column(:evaluate_script, script) + end + rescue => e + tip_exception("上移失败: #{e.message}") + end + end def destroy diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 38aa2812a..44cd8574c 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -69,13 +69,13 @@ class Challenge < ApplicationRecord end # 开启挑战 - def open_game shixun + def open_game shixun, position # 这里的identifier,status是关联了games取了games的identifier,status identifier = self.identifier if identifier.present? shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" else - self.position == 1 ? "/shixuns/#{shixun.identifier}/shixun_exec.json" : "" + position == 1 ? "/shixuns/#{shixun.identifier}/shixun_exec.json" : "" end end