我有一个数组@name = ["D2", "D3"]
,那么如何将其设置select_tag
为选定的选项。
我正在尝试这个,但没有显示
<%= select_tag "add", options_for_select(["D1","D2","D3","D4"],{
@name.each do |id| :selected =>"#{id}" } ), {:multiple => true}
我有一个数组@name = ["D2", "D3"]
,那么如何将其设置select_tag
为选定的选项。
我正在尝试这个,但没有显示
<%= select_tag "add", options_for_select(["D1","D2","D3","D4"],{
@name.each do |id| :selected =>"#{id}" } ), {:multiple => true}
那个怎么样 :
<%= select_tag "add", options_for_select(["D1","D2","D3","D4"],@name), {:multiple => true} %>
你需要这样的东西:
<%= select_tag "add", options_for_select(["D1","D2","D3","D4"], :selected =>["D1","D4"]) , :multiple => true %>
除非你name.id
给你一个“D1”,否则你可能想改变你的方法。哪个字段name
对应“D1”?