Skip to content

Instantly share code, notes, and snippets.

@kuboon
Created November 20, 2015 06:30
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kuboon/f692d9a844c0ff5877c8 to your computer and use it in GitHub Desktop.
Save kuboon/f692d9a844c0ff5877c8 to your computer and use it in GitHub Desktop.
acts_as_taggable_on + simple_form + select2
$(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
gem 'acts-as-taggable-on'
gem 'simple_form'
gem 'select2-rails'
Copy link

ghost commented Oct 25, 2016

Thank you . This is perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment