问题描述
|
假设这种形式:
<% 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,:title) ) %>
<% end %>
当用户选择一个主题时,则必须使用属于所选主题的考试来更新检查选择器列表。
如何将主题参数发送到控制器?我尝试使用:subject_id => 1
发送参数,但是它不起作用。
请建议我一些方法。
如果您需要更多信息,请询问我。
非常感谢你。
问候。
解决方法
嘿,我可以详细回答您的问题。相反,您只应观看此截屏视频:
http://railscasts.com/episodes/88-dynamic-select-menus
它说明了您的需求,并提供了更详细的说明。
希望能帮助到你。
,我更改了选择:
<%= 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