Class: Admin::AutocompleteController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/autocomplete_controller.rb

Instance Method Summary collapse

Instance Method Details

#listObject



5
6
7
8
9
10
# File 'app/controllers/admin/autocomplete_controller.rb', line 5

def list
  model_class = params[:model].camelize.constantize
  field_name = params[:field].to_sym
  entities = model_class.where("#{field_name} ilike ?", "%#{params[:q]}%").order(field_name)
  render :json => entities.map {|e| {:id => e.id, :name => e.send(field_name)}}
end