简体   繁体   中英

Create Nested Forms in Ruby on Rails

I am generating an html.erb file as part of my rails application. In it, I am using FormBuilder's form_for to create one of my main modeled objects. In the course of the page code, though, I also have a form_tag remote Ajax call for another related route.

When I nested these within each other, however, Firefox failed to render the inner form object's enclosing <form> element, and when I tried to fire off that form's action, the page just refreshed itself. Is there an easy way to handle form-inside-form javascript for rails?

I also tried completing the first form, and then later on running a javascript script to .append() the second form to the div that it needs to belong to, but this seemed to break my routing, as Rails could no longer find the template, even though the js.erb file that it is trying to route to is in the same location as it was before.

Thanks, any help is much appreciated! C

Nesting HTML forms is not allowed according to the HTML specs. See this SO question. You should move your inner form out so it becomes a sibling of its current parent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM