如何使用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
,但它不起作用。
请建议我一些方法来做到这一点。
如果您需要更多信息,请询问我。
非常感谢。 问候。
Suppose this form:
<% 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 %>
When user selects a subject, then exams selector list must be updated with exams belongs to selected subject.
How can I send subject parameter to controller? I tried to send parameter using :subject_id => 1
, but it does not work.
Please suggest me some ways to make this.
If you need more info, please ask me.
Thank you very much.
Greetings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嘿,我可以详细地回答你的问题。相反,您应该只观看此截屏视频:
http://railscasts.com/episodes/88-dynamic -select-menus
它解释了您需要什么以及更详细的说明。
希望有帮助。
Hey, I could answer your question with details. Instead you should only watch this screencast:
http://railscasts.com/episodes/88-dynamic-select-menus
It explanins what you need and with more detailed instructions.
Hope it helps.
我改变了我的选择:
并且它有效。 :D
I changed my select:
and it works. :D