acts_as_taggable_on + simple_form + select2
gem 'acts-as-taggable-on'
gem 'simple_form'
gem 'select2-rails'
$(document).on 'ready page:load', ->
$('select.form-control.tags').select2({tags: true});
class TagsInput < SimpleForm::Inputs::CollectionInput
enable :placeholder
def input(wrapper_options = {})
@collection ||= @builder.object.send(attribute_name)
label_method, value_method = detect_collection_methods
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
merged_input_options.reverse_merge!(multiple: true)
@builder.collection_select(
attribute_name, collection, value_method, label_method,
input_options, merged_input_options
)
end
end
# in application.coffee
#= require select2
# in application.scss
*= require select2
*= require select2-bootstrap
# in controller
permit(tag_list: [])
= f.input :tag_list, as: :tags