如何在刷新后保留多个select_tag值?

时间:2013-06-16 16:58:13

标签: ruby-on-rails

如何在刷新后保留多个select_tag的选定值?

<%= select_tag(:cars, options_for_select( [['bmw', 50000], ['audi', 55000], ['fiat', 20000], 0    ), :multiple => true,  :title=> "All Makes", :class => "selectpicker input-small" )  %>

1 个答案:

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

在这种情况下,将选择bmwaudi选项。

更多信息请参阅API参考here