From 21e4d03f0e74c7090b491befdc6d9ade7c0f8028 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Dec 2019 16:25:07 +0800 Subject: [PATCH] =?UTF-8?q?admins=E5=A2=9E=E5=8A=A0=E5=AE=9E=E8=B7=B5?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/schools_controller.rb | 15 ++++++++++++++- config/routes.rb | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index f0dd6dd75..99ca62b4c 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -11,6 +11,19 @@ class SchoolsController < ApplicationController end def for_option - render_ok(schools: School.select(:id, :name).as_json) + schools = School.all + keyword = params[:keyword].to_s.strip + schools = schools.where('name LIKE ?', "%#{keyword}%") if keyword + + render_ok(schools: schools.select(:id, :name).as_json) + end + + def search + schools = School.all + keyword = params[:keyword].to_s.strip + schools = schools.where('name LIKE ?', "%#{keyword}%") if keyword + + schools = paginate(schools) + render_ok(schools: schools.as_json(only: %i[id name province])) end end diff --git a/config/routes.rb b/config/routes.rb index f2b1342e0..8066f8699 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -713,6 +713,7 @@ Rails.application.routes.draw do collection do get :school_list get :for_option + get :search end scope module: :ecs do