Module: ActiveAdmin::SearchableSelect::ResourceDSLExtension

Defined in:
lib/activeadmin/searchable_select/resource_dsl_extension.rb

Overview

Mixin for ActiveAdmin resource DSL

Instance Method Summary collapse

Instance Method Details

#searchable_select_options(name: :all, **options) ⇒ Object

Define a collection action to serve options JSON data for searchable selects.

Parameters:

  • scope (ActiveRecord::Relation, Proc)

    Either a collection of records to create options for or a proc returning such a collection. Procs are evaluated in the context of the collection action defined by this method. Procs can optionally take a single params argument containing data defined under the params key of the input's ajax option. Required.

  • text_attribute (Symbol)

    Name of attribute to use as display name and to filter by search term.

  • display_text (Proc)

    Takes the record as parameter. Required if text_attribute is not present.

  • filter (Proc)

    Takes the search term and an Active Record scope as parameters and needs to return a scope of filtered records. Required if text_attribute is not present.

  • name (Symbol) (defaults to: :all)

    Optional collection name if helper is used multiple times within one resource.



29
30
31
32
33
34
35
36
# File 'lib/activeadmin/searchable_select/resource_dsl_extension.rb', line 29

def searchable_select_options(name: :all, **options)
  option_collection = OptionCollection.new(name, options)
  config.searchable_select_option_collections[name] = option_collection

  collection_action(option_collection.collection_action_name) do
    render(json: option_collection.as_json(self, params))
  end
end