views:

548

answers:

1

Hi, 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 (i.e. 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.

+3  A: 

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.

ryanb
Thanks, I love your RailsCasts!
William