Question

What I have is a remote form inside another remote form like this:

<%=form_for @myobj,:as=>:myobj,:url=>{:controller=>"my_controller",:action=>"first_action"},:remote=>true do |f|%>
   <%=form_for @myotherobj,:as=>:myotherobj,:url=>{:controller=>"my_controller",:action=>"second_action"},:remote=>true do |ff|%>
      <%=ff.submit "second"%>
   <%end%>
   <%=f.submit "first"%>
<%end%>

But then I click the second submit it doesn't do a remote call, It does a normal call with leads me to an error Missing Template because my action only responds to JS (Ajax Calls)

Was it helpful?

Solution

Nested forms are invalid html.

The browsers behaviour is undefined what to do in such a case. It's just like trying to use IDs multiple times inside a html document. It will normally be the earliest occurrence of the ID that will be selected by a document.getElementById, and here you are finding the outermost (earliest) form is the one that is submitting.

If (at least) one of the forms is being submitted with javascript, then it would probably be better to create the form elsewhere and copy the values, or move the form elements prior to submitting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top