rails将params中的选定值输入到select_tag(multiple => true)

时间:2013-07-09 10:33:31

标签: ruby-on-rails ruby-on-rails-3.2

我希望保留选择select_tag(:multiple => true)选项,这些选项是用户在执行搜索时选择的

<%= select_tag 'values[]', method_for_options_for_select, :class => 'some-class', :multiple => true, :size => 6 %>

假设用户从select标签中选择4个值,则应选择值, 我们如何将这4个值传递给select_tag?

我尝试使用:selected => params['values[]'],但这不适用于多个真正的

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

参考thisoptions_for_select

如下所示

<%= select_tag 'values[]', 
options_for_select(@stores.map {|s| [s.store_name, s.store_id]}, 
@user.stores.map {|j| j.store_id}),
:class => 'some-class', :multiple => true, :size => 6 %>