我在新文章页面中有一个f.select,它运行正常。但是,当我编辑文章时,值会更改回选项中的第一个值。
有没有办法保留选择值,以便用户在编辑文章时不必担心重做?
这是我的选择标记:
foreach (JProperty property in pin.Properties())
{
if (string.IsNullOrWhiteSpace(property.Value))
{
throw new Exception("Some exception");
//Or perform count for minimum/maximum check
}
}
答案 0 :(得分:1)
您应该在params[:category]
中提供selected: :category
,而不是options_for_select(<...>)
。
答案 1 :(得分:1)
变化:
<%= f.select :category, options_for_select(['drink','food','medicine','supplement','drug','ingredient','lifestyle','other'], params[:category]), {}, { :class => 'span3 controls controls-row' } %>
为:
<%= f.select :category, options_for_select(['Mare', 'Stallion', 'Gelding'], :selected => f.object.category), {}, { :class => 'span3 controls controls-row' } %>