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

Mr_*_*zle 4 select ruby-on-rails 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')"})

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

对此有何帮助?

谢谢.尼兹勒先生

Boh*_*dan 14

你帮忙的格式是

select(object, method, choices, options = {}, html_options = {}) 
Run Code Online (Sandbox Code Playgroud)

所以试试吧

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

并检查您的版本的HTML输出