rails selectize.js include_blank 或自动完成:false

rails selectize.js include_blank or autocomplete: false

问题:当我输入 client/_form.haml 时,selectize.js 自动选择了一个组,而我希望该字段默认为空白,除非我开始输入或输入下拉菜单。

我正在使用 gem "selectize-rails"

学生有很多组。

Main.js:

/*global $*/
/*global app*/
$(document).ready(function(){
    if ($('.selectize')){
        $('.selectize').selectize({
            sortField: 'text'
        });
    }

});

student/_form.haml:

= simple_form_for(@client_group) do |f|
  .form-inputs
    = f.input :client_name
    = f.select :group_id, Group.all.map{|c| [c, c.id]}, {},class: 'selectize'
  .form-actions
    = f.button :submit, class: 'btn btn-primary'

添加 include_blank: true 解决了问题:

= f.select :group_id, Group.all.map{|c| [c, c.id]}, {include_blank: true},class: 'selectize'