我正在尝试使用以下代码设置默认值。未设置默认值。这有什么问题?
= f.select(:on,Admin::DispatcherCondition.ons.collect {|p| [ p[0].humanize, p[0] ] },{default: @admin_dispatcher.on},{class: "form-control chosen-select"})
%td
= f.select(:condition_type, Admin::DispatcherCondition.condition_types.collect {|p| [ p[0].humanize, p[0] ] },{:selected=> @admin_dispatcher.condition_type},{class: "form-control chosen-select"})
答案 0 :(得分:0)
试试这个
= f.select(:on,options_for_select(Admin::DispatcherCondition.ons.collect {|p| [ p[0].humanize, p[0] ] }, f.object.on),{},{class: "form-control chosen-select"})
p[0]
必须包含一个值@admin_dispatcher.on
以供默认选择。
这项工作我刚试过。