From 4c45518913b614628949cacf0cffb5a87c297de0 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 29 Nov 2016 10:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=90=9C=E7=B4=A2=E8=8B=B1=E6=96=87=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E7=9A=84=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 1f8cdd275..d8fc9ce28 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -175,8 +175,10 @@ class AdminController < ApplicationController def courses @name = params[:name].to_s.strip.downcase if @name && @name != "" - @courses = Course.select{ |course| course.teacher && ((course.teacher.show_name).include?(@name) || course.name.include?(@name))} - @courses = @courses.sort{|x, y| y.created_at <=> x.created_at} + all_user_ids = Course.all.map{|course| course.tea_id} + user_str_ids = search_user_by_name all_user_ids, @name + user_ids = user_str_ids.empty? ? "(-1)" : "(" + user_str_ids.join(",") + ")" + @courses = Course.where("tea_id in #{user_ids} or name like '%#{@name}%'").reorder("created_at desc") else @courses = Course.order('created_at desc') end