2011-05-23 58 views
0

假設這種形式:如何使用remote_function將主題參數發送給控制器?

<% form_for(@student) do |f| %> 
<%= f.select(:subject_id, 
      options_from_collection_for_select(@subjects, :id, :name), 
      {:prompt => 'Select a subject' }, 
      {:onChange => "#{remote_function(:update => :student_exam_id, 
                 :url => { 
                  :action => :update_exams_list, 
                  :subject_id => 1 
                 } 
              ) 
          }" }) %> 
<%= f.select(:exam_id, 
      options_from_collection_for_select(@exams, :id, :title)) %> 
<% end %> 

當用戶選擇一個對象,則檢查選擇列表必須與考試更新屬於所選主題。

如何將主題參數發送給控制器?我嘗試使用:subject_id => 1發送參數,但它不起作用。

請給我一些方法來做到這一點。

如果您需要更多信息,請詢問我。

非常感謝。 問候。

回答

0

我改變了我的選擇:

<%= f.select(:subject_id, 
      options_from_collection_for_select(@subjects, :id, :name), 
      {:prompt => 'Select a subject' }, 
      {:onChange => remote_function(:update => :student_exam_id, 
              :url => { :action => :update_exams_list }, 
              :with => "'subject_id=' + this.value") }) %> 

和它的作品。 :D

1

嘿,我可以用細節回答你的問題。相反,你應該僅看這個截屏:

http://railscasts.com/episodes/88-dynamic-select-menus

它explanins您需要什麼,有更詳細的說明。

希望它有幫助。

+0

非常感謝,這是一種靜態方式,但我需要它使用異步請求。 – Israel 2011-05-24 02:33:49

相關問題