2009-09-30 87 views
0

我在index.html(上傳控制器)中保存了這段代碼這是一個示例。Ruby on Rails中的Javascript onchange事件的問題

<p> 
    <label for="picture_city">City:</label> 
<%= form.select :city, Picture::CITIES, :onchange => remote_function(:url => {:action => 'update_universities'}, :with => '') %> 
</p> 

當我去上傳/索引表單加載好,沒有錯誤。但是當我在html中看到生成的代碼時,我看不到onchange屬性。這是神祕的,請幫我解決這個問題!

<p> 

    <label for="picture_city">City:</label> 
<select id="picture_city" name="picture[city]"><option value="1">New York</option> 
<option value="2">Boston</option> 
<option value="3">Chicago</option> 
<option value="4">Detroit</option> 
<option value="5">Washington</option></select> 
</p> 

問題在哪裏??? 有人知道嗎?

回答

0

形成正確選擇格式:

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

類似的東西:

<%= form.select :obj, :city, Picture::CITIES, {:onchange => remote_function(:url => {:action => 'update_universities'}, :with => '')} %> 
+0

它diidn't幫助。 我仍然無法看到HTML源代碼中的onchage屬性。 – Anton 2009-09-30 08:58:06

+0

請幫助這個代碼! – Anton 2009-09-30 09:27:07

+0

也許應該在這裏使用文字命名屬性? select ....:html_options => {:onchange =>'alert(「asd」);' } – Anatoliy 2009-09-30 09:32:57