2010-12-19 15 views
4

私は、選択ボックスに私の国のテーブルを表示するには、次のコードを持っている:Ruby on Railsの「選択」ヘルパーにhtml_optionsを設定するにはどうすればよいですか?

 

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

をし、私が試した国が選択されたESとき... 「をのonchange」アクションを設定したい:

 

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 = {}) 

ので、これは、1(Y)である

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

を試してみても、あなたのバージョン

+1

のHTML出力を確認しています。完璧に働いた! –

関連する問題