如何使用remote_function将主题参数发送到控制器?

发布于 2024-11-09 14:29:07 字数 1008 浏览 3 评论 0原文

假设这种形式:

<% 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小傻瓜 2024-11-16 14:29:07

嘿,我可以详细地回答你的问题。相反,您应该只观看此截屏视频:

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.

被你宠の有点坏 2024-11-16 14:29:07

我改变了我的选择:

<%= 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

I changed my select:

<%= 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") } ) %>

and it works. :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文