2011-05-23 97 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

相关问题