Added to gemfiles

 gem 'bootstrap_tokenfield_rails' 

Added to application.js:

 //= require bootstrap-tokenfield 

Added application.scss

 @import bootstrap-tokenfield 

Using form_for I try to use it in the view, but the field as it was an ordinary select has remained.

 <%= f.select :tag_ids, Tag.all.collect {|t| [t.name, t.id]}, {}, multiple: true, class: 'tokenize' %> 
  • Because, according to the documentation that needs to be read carefully , the field must also be initialized from JS. - D-side
  • @ D-side, that's the problem. I have a sass. And on the site css - Radzhab
  • You have obvious problems with attention, do I have a word about CSS? :) - D-side
  • sorry) reworked today. - Radzhab
  • @ D-side So how to initialize it? * - Radzhab

2 answers 2

In application.js add this to initialize the plugin:

 $(function () { $('input.tokenize').tokenfield(); }); 
  • and how to be with <input type = "text" class = "tokenize">? how to declare it using form_for - Rajab
  • @Radzhab I can’t understand how you want to do it (do you want to make a sample from this select on this input?
  • @AndrewTymchenko I have <select multiple = "multiple" and I need to get <input type = "text" - Radzhab

I understand you need to default values

 <input type="text" class="form-control" id="tokenfield" value="что, то"/> 

and make autocomplete

file1.js.erb

  $('#tokenfield').tokenfield({ autocomplete: { source: [<%= Tag.all.collect {|t| t.name } %>], delay: 100 }, showAutocompleteOnFocus: true })