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.
I'm not sure if I totally understand your problem but would a wizard help? There's a great talk about wizards here: http://confreaks.tv/videos/railsconf2014-ultra-light-and-maintainable-rails-wizards and follow-up blog post here: http://www.codepainter.ca/2013/10/ultra-light-maintainable-wizards-in.html
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 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.