如何在Ruby on Rails中为'select'助手设置html_options?

问题描述:

我有一个代码在一个选择框来显示我的国家表:如何在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先生

这个助手的喜格式

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