2012-08-24 36 views
0

我只是想爲select設置未定義的值。通過undefined我的意思是「未定義」一個,但不僅是默認的一個。未定義的值在Ruby on Rails中選擇

我有這樣的:

= form_for @address do |f| 
    = f.select :country_id, [['no country selected','0']] + Country.as_key_value_array 

其中Country.as_key_value_array返回[['country1','1'], ['country2','3'],['country3','3']]

數組是否有任何其他的方式來達到我想要什麼?

回答

2

f.select :country_id, "<option value='0'>no country selected</option>".html_safe + options_from_collection_for_select(Country.all, :id, :name)

0

檢查了這一點,

= f.select :country_id, options_for_select([['no country selected','0']] + Country.as_key_value_array) 
+0

這是比較複雜的話,我有。我的方法也在起作用。 – Alexandre

相關問題