22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/bootstrap3_autocomplete_input/controllers/autocomplete.rb', line 22
def autocomplete(object, method, options = {})
define_method("autocomplete_#{object}_#{method}") do
method = options[:column_name] if options.has_key?(:column_name)
q = params[:q]
class_name = options[:class_name] || object
model = get_object(class_name)
if q && q.present?
items = get_autocomplete_items(:model => model, :options => options, :q => q, :method => method)
elsif params[:q].nil?
items = get_autocomplete_items(:model => model, :options => options, :q => '', :method => method)
end
render :json => items_to_json(items, options[:display_value] ||= method)
end
end
|