Class: AutoComplete
- Inherits:
-
Object
- Object
- AutoComplete
- Defined in:
- app/lib/auto_complete.rb
Overview
this class runs a simple like query against the database in order to generate autocomplete (typeahead) items for the frontend. there is questionable scalability of this class, so it's suggested to either debounce or throttle client requests.
Class Method Summary (collapse)
Class Method Details
+ (Object) find_institutions(institution)
17 18 19 20 21 |
# File 'app/lib/auto_complete.rb', line 17 def self.find_institutions(institution) @institution = "%#{institution}%".downcase @response = Institution.where("name LIKE ?", @institution) return {'institutions' => @response} end |
+ (Object) find_names(name)
8 9 10 11 12 13 14 15 |
# File 'app/lib/auto_complete.rb', line 8 def self.find_names(name) @name = "%#{name}%".downcase @response = Person.where("name LIKE ?", @name) .where('approved' => true) .includes(:institution) @institutions = Set.new return @response end |