rails select_tag with 2d options_for_select默认值

时间:2015-08-04 19:51:49

标签: ruby-on-rails forms

我有一个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"不起作用。

1 个答案:

答案 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" ))