Rails:从submit_tag更改表单操作
我有一个表单,它始终将表单提交到控制器中的“更新”功能,并且我使用“remote_form_for”标签创建了此表单。在此表单中,我有来自不同表的对象,并且我想通过 AJAX 请求将整个表单数据提交到另一个函数(而不是“更新”函数)。
我尝试了很多方法,包括使用带有操作的提交标签
<% remote_form_for @employee, :url => organization_employee_path(@organization, @employee), :method => :put do |employee_form| %>
// form objects and other functionalities
....
....
// views inside the forms
<div id="employee_header_div">
<%= render :partial => "employee_header", :locals => {:employee => @employee} %>
</div>
...
...
<%= submit_tag "page_level_validation", :id => "page_level_validation" , :action=>"validate"%>
<% end %>
,但 Ajax 请求总是调用相同的“更新”函数。
如果有人帮助解决这个问题,那将非常有帮助。
I have a form which is always submitting the form to the "update" function in the controller, and I have created this form using "remote_form_for" tag. In this form I have objects from different tables, and from this form I want to submit entire form data to another function(not to the "update" function) via AJAX request.
I have tried many methods including using submit tag with action
<% remote_form_for @employee, :url => organization_employee_path(@organization, @employee), :method => :put do |employee_form| %>
// form objects and other functionalities
....
....
// views inside the forms
<div id="employee_header_div">
<%= render :partial => "employee_header", :locals => {:employee => @employee} %>
</div>
...
...
<%= submit_tag "page_level_validation", :id => "page_level_validation" , :action=>"validate"%>
<% end %>
But the Ajax request always calling the same "update" function.
It would be very helpful, if anyone helps to resolve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能将提交设置为指向主表单指定的不同位置(除非您想使用 HTML5 formaction 属性并处理浏览器兼容性后果)。
但是,您可以做的是在控制器中创建一个新操作来处理这种情况。
例如。
在你的控制器中
不要忘记添加适当的路由。
You can't set the submit to point to a different place than the main form has specified (unless you want to use the HTML5 formaction attribute and deal with the browser compatibility consequences).
However, what you could do is create a new action in your controller which deals with the situation.
e.g..
in your controller
not forgetting to add the appropriate routes.
试试这个:
Try this: