Update customers_controller.rb

This commit is contained in:
2017-01-29 19:35:45 -05:00
committed by GitHub
parent a06599b7f9
commit eca2b986a9

View File

@@ -32,18 +32,7 @@ class CustomersController < ApplicationController
default_search_scope :names
def auto_complete
@customers = []
q = (params[:q] || params[:term]).to_s.strip
if q.present?
if q.match(/\A#?(\d+)\z/)
@customers << Customer.find_by_id($1.to_i)
end
@customers += Customer.where("LOWER(#{Customer.table_name}.name) LIKE LOWER(?)", "%#{q}%").order("#{Customer.table_name}.id DESC").limit(10).to_a
@customers.compact!
end
render :layout => false
end
autocomplete :customer, :name
# display a list of all customers
def index