0
我試圖傳遞給我的select_tag兩個固定值和循環值。我完全可以寫類似:將一個集合旁邊的固定值傳遞給一個options_for_select in rails
<%= select_tag "", options_for_select(session[:user_hotel_list].collect{ |hotel| [hotel["name"], hotel["id"]] }) %>
這裏hotel["name"]
將顯示值和hotel["id"]
領域的「真正價值」。
但是,如果我嘗試添加額外的固定值到我的options_for_select我沒有得到所需的輸出。比方說,我想添加一個選擇「所有酒店」的值爲「全部」。我會嘗試這樣的事情:
<%= select_tag "", options_for_select([["all hotels", "all"], session[:user_hotel_list].collect{ |hotel| [hotel["name"], hotel["id"]] }]) %>
但在這裏,我會得到一個數組作爲集合輸出...
我該如何正確額外固定數據添加到options_for_select與軌道的集合?
EDIT
例如這樣的代碼:
<%= select_tag "dash_select", options_for_select([["all hotels", "all"], ["other", "value"]] << session[:user_hotel_list].collect{ |hotel| [hotel["name"], hotel["id"]] }) %>
顯然[ 「plaze」,31]心不是好!
我真的需要添加多個項目,他們每個人給的值... –
怎麼樣'options_for_select([「所有的酒店」,「全」] ,[「other」,「value」]] << session [:user_hotel_list] .collect {| hotel | [hotel [「name」],hotel [「id」]]})' –
不, 。看我的編輯 –