From aa25f4bf49e97c69c00a2d322638a52a56573e63 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 29 May 2019 15:11:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=AE=9E=E8=AE=AD=E9=A2=98?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8C=89=E6=A0=87=E7=AD=BE=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 7d70b487..1a7fb58a 100755 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -157,8 +157,17 @@ class ExerciseController < ApplicationController else none_shixun_ids = ShixunSchool.where("school_id != #{User.current.user_extensions.try(:school_id)}").pluck(:shixun_id) end - @shixuns = Shixun.where("status = 2 and challenges_count = 1 and id not in (#{none_shixun_ids.join(",")})"). - where("name like ?", "%#{search}%").select{|shixun| shixun.challenges.where(:st => 1).count == 0} + + if search.blank? + @shixuns = Shixun.where("shixuns.status = 2 and challenges_count = 1 and shixuns.id not in (#{none_shixun_ids.join(",")})"). + select{|shixun| shixun.challenges.where(:st => 1).count == 0} + + else + @shixuns = Shixun.joins(challenges: :challenge_tags).where("shixuns.status = 2 and challenges_count = 1 and shixuns.id not in (#{none_shixun_ids.join(",")})"). + where("shixuns.name like ? or challenge_tags.name like ?", "%#{search}%", "%#{search}%").select{|shixun| shixun.challenges.where(:st => 1).count == 0} + + end + @limit = 10 @total_pages = (@shixuns.count / 10.0).ceil @shixuns = paginateHelper @shixuns, @limit