This post seems good for how to create two models with one form. But how would you do it if the two models share one or more of the attributes?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That post seems fairly outdated, I would recommend using
accepts_nested_attributes_forandfields_forin your form instead. That said, overlapping attributes should probably be set in your model’s callbacks. Say you want a project’s name to be automatically set to first task’s name.If your 2 models are completely unrelated, you can assign certain params to them directly in the controller.
Although this is not a great practice, this logic should ideally be moved into models.