From 3685c386db39dd67afbddecef2f0f58a09dd5d9a Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 14 May 2019 20:09:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=B8=B4=E6=97=B6=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 2 +- app/models/challenge.rb | 8 ++++++++ app/views/challenges/_content_list.html.erb | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 344976ab..bf01ffb0 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,7 +2,7 @@ class ChallengesController < ApplicationController layout "base_shixun" # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 - before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index] + # before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index] before_filter :check_authentication, :except => [:index] before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose] diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 5180c8fa..6f4cccfd 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -24,6 +24,14 @@ class Challenge < ActiveRecord::Base scope :choose_type, lambda{where(st: 1)} scope :practice_type, lambda{where(st: 0)} + def shixun_done_new + self.games.map{|game| game.status == 2 }.size + end + + def shixun_running_new + self.games.map{|game| game.status != 2 }.size + end + def game_difficulty str = "简单" case self.difficulty diff --git a/app/views/challenges/_content_list.html.erb b/app/views/challenges/_content_list.html.erb index bc7743de..f9ac88b8 100644 --- a/app/views/challenges/_content_list.html.erb +++ b/app/views/challenges/_content_list.html.erb @@ -73,8 +73,8 @@
- <%= shixun_done(@shixun, challenge.position).to_i %> 人完成挑战 - <%= shixun_running(@shixun, challenge.position).to_i %> 人正在挑战 + <%= challenge.shixun_done_new.to_i %> 人完成挑战 + <%= challenge.shixun_running_new.to_i %> 人正在挑战 <% if challenge.st != 0 %> 经验值 <%= challenge.choose_score %> <% else %>