优化调试代码

newyslclassrooms
daiao 5 years ago
parent 1cf8c32188
commit 9e7785e673

@ -79,16 +79,6 @@ class Challenge < ApplicationRecord
end end
end end
# 开启挑战
def open_game user_id, shixun
game = self.games.where(user_id: user_id).first
if game.present?
shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
else
self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : ""
end
end
# # 开启挑战 # # 开启挑战
# def open_game(user_id, shixun) # def open_game(user_id, shixun)
# #
@ -120,24 +110,6 @@ class Challenge < ApplicationRecord
end end
end end
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status user_id
# todo: 以前没加索引导致相同关卡,同一用户有多个games
# 允许跳关则直接开启
game = games.where(user_id: user_id).take
if game.blank?
position == 1 ? 1 : 0
else
if game.status == 3
shixun.task_pass ? 1 : 0
elsif game.status == 2
2
else
1
end
end
end
def tags_show def tags_show
if self.challenge_tags.nil? if self.challenge_tags.nil?
"--" "--"

@ -19,8 +19,7 @@ if @challenges.present?
json.passed_count challenge.user_passed_count json.passed_count challenge.user_passed_count
json.playing_count challenge.playing_count json.playing_count challenge.playing_count
json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
#json.open_game challenge.open_game json.open_game challenge.open_game
challenge.open_game(@user.id, @shixun)
if @editable if @editable
json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
@ -28,7 +27,6 @@ if @challenges.present?
json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position
end end
#json.passed challenge.has_passed?(@user.id) #json.passed challenge.has_passed?(@user.id)
#json.status challenge.user_tpi_status json.status challenge.user_tpi_status
json.status challenge.user_tpi_status @user.id
end end
end end

Loading…
Cancel
Save