From 61747f8e840675f796de679fcf99b48cef8807a7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 12:25:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7=E5=92=8C?= =?UTF-8?q?=E9=97=AE=E5=8D=B7=E7=AD=94=E9=A2=98=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 10 ++-------- app/controllers/polls_controller.rb | 10 +++------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index ff4dc6be9..2761523a6 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1278,14 +1278,8 @@ class ExercisesController < ApplicationController #搜索 if params[:search].present? - search_content = params[:search] - #搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号 - nick_name_search = @exercise_users_list.where(user_id: User.where('CONCAT(users.lastname, users.firstname) like ?',"%#{search_content}%")) - if nick_name_search.present? - @exercise_users_list = nick_name_search - else - @exercise_users_list = @exercise_users_list.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{search_content}%","%#{search_content}%") - end + + @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") end @export_ex_users = @exercise_users_list diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index cd9679972..90ca1778e 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1026,13 +1026,9 @@ class PollsController < ApplicationController #搜索 if search_content.present? - #搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号 - nick_name_search = @poll_users_list.where(user_id: User.where('CONCAT(users.lastname, users.firstname) like ?',"%#{search_content}%")) - if nick_name_search.present? - @poll_users_list = nick_name_search - else - @poll_users_list = @poll_users_list.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{search_content}%","%#{search_content}%") - end + + @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") + end @poll_users_size = @poll_users_list.count