Class: AutoCompleteController

Inherits:
ApplicationController show all
Defined in:
app/controllers/auto_complete_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user

Instance Method Summary (collapse)

Instance Method Details

- (Object) index



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/auto_complete_controller.rb', line 2

def index
  if params.has_key?(:name) && params.has_key?(:institution)
    render json: { errors: ['cannot contain name and institution params'] }, status: :bad_request
  elsif params.has_key?(:name)
    @response = AutoComplete.find_names(params[:name])
    render :json => @response.as_json
  elsif params.has_key?(:institution)
    @response = AutoComplete.find_institutions(params[:institution])
    render :json => @response.to_json
  else
    render json: { errors: ['must contain a name or instituion param'] }, status: :bad_request
  end

end