rails simple_form 阻止 select 默认向集合添加空白
rails simple_form prevent select adding a blank by default to collection
我正在使用 simple-form
gem 中的集合渲染一个字符串数组,我有 gone through this answer,但那里的解决方案效果不佳。
这是标签
<%= f.input :training_modes, collection: get_training_modes, include_blank: false, input_html: { multiple: true } %>
但是当我通过这个select保存时,我得到了这样的数组
["", "Instructor Led Training", "Webex"]
您需要通过 include_hidden: false
选项和 select 来删除隐藏字段
<%= f.input :training_modes, collection: get_training_modes, include_blank: false, include_hidden: false, input_html: { multiple: true } %>
希望对您有所帮助!
我正在使用 simple-form
gem 中的集合渲染一个字符串数组,我有 gone through this answer,但那里的解决方案效果不佳。
这是标签
<%= f.input :training_modes, collection: get_training_modes, include_blank: false, input_html: { multiple: true } %>
但是当我通过这个select保存时,我得到了这样的数组
["", "Instructor Led Training", "Webex"]
您需要通过 include_hidden: false
选项和 select 来删除隐藏字段
<%= f.input :training_modes, collection: get_training_modes, include_blank: false, include_hidden: false, input_html: { multiple: true } %>
希望对您有所帮助!