2013-05-16 89 views
-1

我有一個陣列@name = ["D2", "D3"],所以如何將其設置爲select_tag作爲選定的選項。用select_tag顯示多個選定的值?

我對這個很努力,但沒有顯示該

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

這是什麼都使用JavaScript或jQuery的呢?請不要噴塗標籤。只使用問題的相關標籤。 –

回答

1

你需要的東西是這樣的:

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

除非你name.id給你一個「D1」,你可能想改變你的做法。 name中的哪個字段對應「D1」?

2

什麼有關:

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

+1

@ user2342350,請注意,所有這些選項都不會有任何'value' [通常不需要] – kiddorails