Note: Posting this as a separate question as per Brian's comment (from http://stackoverflow.com/questions/892624/how-to-handle-multiple-models-in-a-rails-form)
I'm trying to learn the best way to handle multiple models in a single rails form, when the models are both nested and non-nested. For the nested ones, I found these two tutorials to be helpful
http://weblog.rubyonrails.org/2009/1/26/nested-model-forms http://railsforum.com/viewtopic.php?id=717
My questions are:
- In the case of a non-nested model, how to handle multiple entries for the second model? Just run a loop, and use fields_for?
- In both nested/non-nested cases, how to validate for duplicate values, when there are multiple entries for the second model? For example, if project is the primary and task is the secondary (child) model, and the user adds multiple tasks for the project, how to make sure there aren't duplicate tasks added, for that particular model? One way would be to loop through the text values, and check for duplicates. Is there a better way to do it, at the object level, instead of string level?