ActiveAdminAutoSelect

This gem is a little widget which combines Select2, PostgeSQL and ActiveAdmin and helps you filter objects in ActiveAdmin with autocomplete of the selected fields.

Image of AutoSelect Image of AutoSelect

Installation

Add this line to your application's Gemfile:

gem 'admin_auto_select'

And then execute:

$ bundle

Add the following directive to your Javascript manifest file:

//= require autoselect

Usage

After installing the gem, you have to add some lines into the model you want to auto_select. For example, if you want to add the widget to the users id filter:

Call the method defined in the module in order to create the collection_action

first_name, :last_name, :email are the fields which help you find the desired user

 auto_select :first_name, :last_name, :email

Then change the relevant filter in your model

Notice: :id_eq is necessary. data-scope is the desired scope which will be used by the widget in order to fetch the similar users. data-url is also necessary and is the url generated by the action which is defined in the module.

  filter :id_eq, label: "User", input_html: { data: { scope: 'user',
                                                        url: 'users/autoselect',
                                                placeholder: 'Select user'     } }

Instantiate the js class in your active_admin js file with the generated filter input.

newAutoSelect = new AutoSelect(input: $("#q_id_eq))

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/spyrbri/admin_auto_select. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.