You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/controllers/schools_controller.rb

30 lines
792 B

6 years ago
class SchoolsController < ApplicationController
def school_list
schools = School.all
6 years ago
search = params[:search].to_s.strip
if search.present?
schools = schools.where('name Like ?', "%#{search}%")
end
6 years ago
render_ok(school_names: schools.pluck(:name))
6 years ago
end
def for_option
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
5 years ago
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
6 years ago
end