上移下移的问题

PCqiandao
daiao 5 years ago
parent 930d622760
commit 792b87b0eb

@ -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

@ -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

Loading…
Cancel
Save