diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e352d6cec..d1d2499f0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -70,6 +70,8 @@ module ApplicationHelper # shixun开启挑战对应的行为名及url def task_operation_url current_myshixun, shixun + return ["开启挑战", "/shixuns/#{shixun.identifier}/shixun_exec"] unless current_user.logged? + if current_myshixun.blank? name = shixun.status == 0 ? "模拟实战" : "开启挑战" url = "/shixuns/#{shixun.identifier}/shixun_exec" diff --git a/app/models/shixun.rb b/app/models/shixun.rb index c3c5cec78..b9bd372b0 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -210,8 +210,9 @@ class Shixun < ApplicationRecord end # 当前用户开启的实训 - def current_myshixun(user_id) - myshixuns.find_by(user_id: user_id) + def current_myshixun(user) + return nil unless user.logged? + myshixuns.find_by(user_id: user.id) end # 实训技术平台 @@ -264,7 +265,7 @@ class Shixun < ApplicationRecord # 实训关卡的总分(由于大部分是实践题,因此没关联查choose表) # 提前加载问题:由于选择题比较少,所以几乎不会触发选择题的查询,所以没必要提前载入choose_score def all_score - self.challenges.pluck(:score).sum + self.challenges.sum(:score) end ### fork 数量