【发布时间】:2015-11-23 20:27:22
【问题描述】:
我想将模型中文本字段的输入可能性限制为先前定义的数组。
如何使用像["foo","bar","foobar"] 这样的一维数组创建options_for_select?
我试过了
form_for @mappings do |f|
f.select(:mapping_type, options_for_select(["foo","bar","foobar"]), class: "..."
end
但是选择框出来的都是这样的:
<select name="section_mapping[mapping_type]" id="section_mapping_mapping_type">
与应有的相反:
<select name="mapping_type" >
编辑:
我将f.select 更改为select_tag,表单显示没有任何错误,但是当我提交它时,该字段为空
编辑 2:
f.collection_select(:mapping_type, options_for_select([...]), class: "..."
的工作原理是正确地提交带有值的表单,但不应用 HTML 类。这是为什么呢?
【问题讨论】:
标签: ruby-on-rails forms drop-down-menu html-select