To enable select2 with tags functionality you need to do the following:
f.input :names, as: :tags
You can load previous created tags using collection
option passing an array of strings like this:
f.input :names, as: :tags, collection: ['Julio', 'Emilio', 'Leandro']
To use tagging functionality with Active Record collections you need to do something like this:
class Event < ActiveRecord::Base
has_and_belongs_to_many :performers
end
class Performer < ActiveRecord::Base
has_and_belongs_to_many :events
end
So, in the ActiveAdmin's Event form, you can add:
f.input :performer_ids, as: :tags, collection: Performer.all, display_name: :full_name
Remember: the input name must be:
performer_ids
notperformers
and you need to add topermit_params
theperformer_ids: []
key.
display_name
: (optional) You can pass an optionaldisplay_name
to set the attribute (or method) to show results on the select. It defaults to:name
value
: (optional) You can pass an optionalvalue
to set the attribute (or method) to use when an item is selected. It defaults to:id
width
: (optional) You can set the select input width (px or %).