Ask A Question


You’re not receiving notifications from this thread.

Set up complex forms that user form objects nested within form objects?

Greg Cosgrove asked in General

Context: I'm working on an app for my job with strange requirements. Unfortunately, I have to maintain a data structure that's accessible to legacy CF applications that were originally designed for MSSQL. This has created an issue with model creep creating a lot of duplication. I can't use polymorphic association as I intended because of the legacy requirements. Thus, an app that could have had 20 models now has about 40.

The app has a lot of complex forms nested forms. Originally, I used accepts_nested_attributes_for, but this created validation and other problems because these forms are filled out progressively, not in one sitting. Data has to be validated piece by piece, even within a single model, then revalidated when the large form is completed.

I have abstracted the forms into Form Objects which works well in isolation. It also allows them to be reused in different places in the application. Unfortunately, I'm a little lost on how to aggregate these form objects into a single form and then pass data to the correct models. Any suggestions on strategies for this type of setup?


Greg - Not sure if you're still struggling with this, but I've been playing with doing something similar by building an aggregate form object that pulls together and utilizes all of the component form objects as and when needed. It seems to work, though I haven't quite finished everything yet.


+1 On this, I'm subbed to see what you come up with. If I can help, let me know


I'm not sure if I totally understand your problem but would a wizard help? There's a great talk about wizards here: and follow-up blog post here:

This approach uses a nice way to split out your models into sub-models so you can validate your form data at each step.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,603+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.