rails simple_form 防止选择默认添加空白到集合

Ana*_*sra 2 ruby-on-rails simple-form

我正在使用simple-formgem 中的集合渲染一组字符串,我已经完成了这个答案,但是那里的解决方案效果不佳。

这是标签

<%= f.input :training_modes, collection: get_training_modes, include_blank: false, input_html: { multiple: true } %>
Run Code Online (Sandbox Code Playgroud)

但是当我通过这个选择保存时,我得到了这样的数组

["", "Instructor Led Training", "Webex"]
Run Code Online (Sandbox Code Playgroud)

Raj*_*ngh 6

您需要include_hidden: false使用 select传递选项以删除隐藏字段

<%= f.input :training_modes, collection: get_training_modes, include_blank: false, include_hidden: false, input_html: { multiple: true } %>
Run Code Online (Sandbox Code Playgroud)

希望有帮助!