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

时间:2010-12-19 18:09:30

标签: ruby-on-rails select helper

我有下一个代码在选择框中显示我的国家/地区表:


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

我希望在选择国家/地区时设置'onchange'操作... 我试过了:


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

但没有任何反应......

对此有何帮助?

感谢。 Nizzle先生

1 个答案:

答案 0 :(得分: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')"})

并检查你的版本的html输出