我有一个select_tag
,其中options_for_select
为二维数组的二维数组,因此显示的选项与使用表单发送的内容不同(即options_for_select([["Option A", "this_get_submitted"],["Way Better Option", "this_is_the_other_option"]])
。
如何设置默认选择?
select_tag(:choice, options_for_select(...), selected: "this_is_the_other_option"
不起作用。
答案 0 :(得分:2)
这将有效,options_for_select
中的第二个选项是您要显示的默认选项。
select_tag(:choice, options_for_select([["Option A", "this_get_submitted"],["Way Better Option", "this_is_the_other_option"]], "this_is_the_other_option" ))