The topic doesn't quite explain what I'm trying to do. Picture this...
I have 2 Models - Manufacturers and Types. Manufacturers have many Types. Rather than forcing the user to create the two on seperate pages I'm aiming to combine them in such a way that I can (using RESTful actions) generate a new Manufacturer and add Types to it before the Manufacturer is saved to the database. The idea is the Types don't actually get saved until the Manufacturer is saved.
So my 'new' Manufacturer view contains a AJAX form to add Types but within the controller action I can't seem to figure out how to add these new Types to the Manufacturer model in the view.
Is this even possible? I figured that I could somehow create the Type and push it to the Manufacturer.types but I don't know how to pass the Manufacturer model along to do this.
Me again, still looking for input but one possible solution I've come across would be creating text fields rather than just displaying a list. That would mean I wouldn't actually be associating Types with Manufacturers until the commit.
Ensuring that models are behaving correctly together can be further monitored and/or enforced via ActiveRecord callbacks.
The main problem I would envisage, is if you are using Ajax forms to partly submit data. Maintaining data over multiple submissions is relatively difficult without submitting at least some data to the database. In most systems, there needs to be an object to hold the data between each submission. You could use the session data, but that may be problematic.
Personally, I think if I were building up these object over a number of submissions, I'd add a status field to the manufacturer object, which could be set to incomplete until the whole build process was complete and then build a process that would regularly clean up any incomplete objects.
However, if you are just using Ajax to build the form, and that once the form was built and the data entered, the form was submitted in one action, I don't think you have a problem.
I decided to take another route and follow the "Complex Forms" example as seen on Railscasts.com. Rather than providing a field that would allow the user to enter something and click 'Add' I now use a 'Add' link to generate a new form field. There's no intermediate saving now.
My original use case was someone needing to add multiple child models quickly and easily and they would do this by simply typing in the form field, hitting enter, typing the next child, enter, next, enter, etc. It was getting messy so now the user has to click a link to generate the next form field - which honestly isn't that big of a deal.