From 45a0f6cf2c3d42793b01d2bf99467d687c2ac777 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 20 Jun 2019 19:04:05 +0800 Subject: [PATCH] modify school list apu --- app/controllers/schools_controller.rb | 10 +++++++--- app/views/schools/school_list.json.jbuilder | 1 - .../modules/Courses/coursesPublic/form/SchoolSelect.js | 4 ++-- public/react/src/modules/Courses/new/CoursesNew.js | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) delete mode 100644 app/views/schools/school_list.json.jbuilder diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 1551091aa..11932be42 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -1,8 +1,12 @@ class SchoolsController < ApplicationController + def school_list + schools = School.all + search = params[:search].to_s.strip + if search.present? + schools = schools.where('name Like ?', "%#{search}%") + end - def school_list - q = params[:search] ? params[:search].strip : "" - @schools = School.where("name like ?", "%#{q}%").pluck(:name) + render_ok(school_names: schools.pluck(:name)) end end diff --git a/app/views/schools/school_list.json.jbuilder b/app/views/schools/school_list.json.jbuilder deleted file mode 100644 index 1e2c89897..000000000 --- a/app/views/schools/school_list.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.shools_name @schools \ No newline at end of file diff --git a/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js b/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js index db62c50b6..e1a9062e3 100644 --- a/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js +++ b/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js @@ -34,9 +34,9 @@ class SchoolSelect extends Component{ } }) .then((response) => { - if (response.data.shools_name) { + if (response.data.school_names) { if (currentValue === value) { - callback(response.data.shools_name); + callback(response.data.school_names); } } }) diff --git a/public/react/src/modules/Courses/new/CoursesNew.js b/public/react/src/modules/Courses/new/CoursesNew.js index d8fb83974..6c0158f21 100644 --- a/public/react/src/modules/Courses/new/CoursesNew.js +++ b/public/react/src/modules/Courses/new/CoursesNew.js @@ -314,7 +314,7 @@ class CoursesNew extends Component { } }).then((result)=>{ this.setState({ - searchlistscholl:result.data.shools_name, + searchlistscholl:result.data.school_names, scholl:value }) this.props.form.setFieldsValue({