Skip to content

Commit

Permalink
professor search by name; set up autocomplete route
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Mason committed May 12, 2016
1 parent 5d028eb commit a8227b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/controllers/professors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ProfessorsController < ApplicationController
def autocomplete
@professors = Professor.search(params[:term])
respond_to do |format|
format.json do
render json: @professors.map { |p| { id: p.id, label: p.name } }
end
end
end
end
1 change: 1 addition & 0 deletions app/models/professor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ def TBA
end

scope :order_by_realness, -> { order('CASE WHEN("name" = \'Staff\' OR "name" = \'TBA\') THEN 1 ELSE 0 END') }
scope :search, ->(q) { where("\"name\" LIKE '%#{q}%'") }
end
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
end
end

resources :professors, only: [] do
collection do
get :autocomplete
end
end

get 'scheduler' => 'scheduler#index'
post 'scheduler' => 'scheduler#create'
delete 'scheduler' => 'scheduler#destroy'
Expand Down

0 comments on commit a8227b5

Please sign in to comment.