rails simple_form阻止选择默认情况下将空白添加到集合

时间:2016-09-10 04:25:30

标签: ruby-on-rails simple-form

我使用simple-form gem中的集合渲染字符串数组,我是gone through this answer,但那里的解决方案效果不佳。

这里是标签

<%= f.input :training_modes, collection: get_training_modes, include_blank: false, input_html: { multiple: true } %>

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

["", "Instructor Led Training", "Webex"]

1 个答案:

答案 0 :(得分:3)

您需要将include_hidden: false选项与select一起移除隐藏字段

<%= f.input :training_modes, collection: get_training_modes, include_blank: false, include_hidden: false, input_html: { multiple: true } %>

希望有所帮助!

相关问题