在代码中,我有:
<%= form_for(:category,:url=>{:action=>'update',:id=>@category.id}) do |f|%>
<div class="field">
<b style="color: #808080;"> Cuisine name: </b>
<%= f.select :cuisine_id,options_from_collection_for_select(@cuisines,"id","cuisine_name"),prompt:'select cuisine' %>
我正在使用此表单更新“ cuisine_name”。问题是我想将此字段设置为默认值。现在我正在获取所有可用值。
你快到了。从文档:
options_from_collection_for_select(collection, value_method, text_method, selected = nil)
因此您需要再传递一个参数来创建一个默认情况下处于选中状态的选项
options_from_collection_for_select(@cuisines,"id","cuisine_name", <your thing here>)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句