如何在刷新后保留多个select_tag的选定值?
<%= select_tag(:cars, options_for_select( [['bmw', 50000], ['audi', 55000], ['fiat', 20000], 0 ), :multiple => true, :title=> "All Makes", :class => "selectpicker input-small" ) %>
答案 0 :(得分:1)
您可以将所选值列表作为第二个选项传递给options_for_select
:
<%= select_tag(:cars,
options_for_select([['bmw', 50000],
['audi', 55000],
['fiat', 20000]],
[55000, 50000]),
:multiple => true, :title=> "All Makes",
:class => "selectpicker input-small" ) %>
在这种情况下,将选择bmw
和audi
选项。
更多信息请参阅API参考here。