简体   繁体   中英

Multi-level Complex Rails Forms

I'm trying to create a multi-level ajax form on my rails app that can add/remove fields associated with a new object in a form when a button is clicked. However, I need to have multiple levels to this form (ie if someone adds a "Meal" object, there must also be a button inside the created "Meal" form for "Add a food".)

I followed this tutorial (parts 1-3) by Ryan Bates ( http://railscasts.com/episodes/73-complex-forms-part-1 ), but it only describes a single level form. The prototype helper commands for rails do not allow me to put javascript inside javascript however (there is an issue with escaping the characters properly). How else can I create a form like this? Thanks.

The technique in the episodes does not support deep nesting. However, Rails 2.3 introduced a new way to handle multi-model forms called accepts_nested_attributes_for which does support deep nesting. Unfortunately the full solution is too involved to cover here, but I do plan to cover it in future Railscasts episodes.

In the meantime, I recommend checking out Eloy Duran's example application which shows how to handle deep nesting in Rails 2.3.

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