-1

我有一个数组@name = ["D2", "D3"],那么如何将其设置select_tag为选定的选项。

我正在尝试这个,但没有显示

<%= select_tag "add", options_for_select(["D1","D2","D3","D4"],{
@name.each do |id| :selected =>"#{id}" } ), {:multiple => true}
4

2 回答 2

2

那个怎么样 :

<%= select_tag "add", options_for_select(["D1","D2","D3","D4"],@name), {:multiple => true} %>

于 2013-05-16T11:57:53.030 回答
1

你需要这样的东西:

<%= select_tag "add", options_for_select(["D1","D2","D3","D4"], :selected =>["D1","D4"]) , :multiple => true %>

除非你name.id给你一个“D1”,否则你可能想改变你的方法。哪个字段name对应“D1”?

于 2013-05-16T11:52:02.637 回答