Skip to content

Instantly share code, notes, and snippets.

@wykhuh
Created May 25, 2018 23:21
Show Gist options
  • Save wykhuh/c6c1fbb3017d72b0bbb5b4233e4edcbc to your computer and use it in GitHub Desktop.
Save wykhuh/c6c1fbb3017d72b0bbb5b4233e4edcbc to your computer and use it in GitHub Desktop.
autocomplete
class AutocompleteController < ApplicationController
def index
query = params[:query].downcase
taxa = ::Taxon.where('lower("name") like ?', "#{query}%")
.limit(10)
render json: taxa
end
end
class AddTaxaIndex < ActiveRecord::Migration[5.0]
def change
execute 'CREATE INDEX name_prefix ON taxa USING btree (lower ("name") text_pattern_ops);'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment