2010-12-19 92 views
4

我有一個代碼在一個選擇框來顯示我的國家表:如何在Ruby on Rails中爲'select'助手設置html_options?

 

f.select("country_id", Country.all.collect {|p| [ p.name, p.id ] }, {:include_blank => 'Select a Country'}) 
 

,我想,當ES選擇一個國家設定一個'平變化的行動...... 我已經試過:

 

f.select("country_id", Country.all.collect {|p| [ p.name, p.id ] }, {:include_blank => 'Select a Country',:onchange=>"alert('foo')"}) 
 

但沒有任何反應....

對此有何幫助?

謝謝。 Nizzle先生

回答

14

這個助手的喜格式

select(object, method, choices, options = {}, html_options = {}) 

所以儘量

f.select("country_id", Country.all.collect {|p| [ p.name, p.id ] }, {:include_blank => 'Select a Country'},{:onchange=>"alert('foo')"}) 

,並檢查你的版本

+1

HTML輸出這是一個(Y)。完美解決! – 2010-12-19 19:16:21