Module: SimpleFormPolymorphicAssociations::Controller::AutocompleteConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/concerns/simple_form_polymorphic_associations/controller/autocomplete_concern.rb
Overview
Example:
# app/controllers/people_controller.rb
class PeopleController < ApplicationController
include SimpleFormPolymorphicAssociations::AutocompleteConcern
end
Instance Method Summary collapse
Instance Method Details
#autocomplete ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/concerns/simple_form_polymorphic_associations/controller/autocomplete_concern.rb', line 13 def autocomplete @collection = if params[:term].present? load_collection_scope.autocomplete(params[:term]) else [] end respond_to do |format| format.json { render json: { results: @collection.map { |q| q.as_autocomplete_json } } } end end |