From 4529684d66aed631d3069de4f07414fac03fb987 Mon Sep 17 00:00:00 2001
From: daiao <358551898@qq.com>
Date: Tue, 10 Mar 2020 02:16:11 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/helpers/application_helper.rb | 2 ++
 app/models/shixun.rb              | 7 ++++---
 2 files changed, 6 insertions(+), 3 deletions(-)

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 数量