Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit multiple models in one form?

I got a task from my trainer. I want to edit two models in one form. For example, we have two entities student and address. In the new student part i want to add both student details and address. How can i achieve this through scaffolding in ruby on rails?

like image 967
Nithin Viswanathan Avatar asked Oct 31 '12 05:10

Nithin Viswanathan


1 Answers

You can use accepts_nested_attributes_for and fields_for to build a form to create two model at same time, so you can edit them too. This kind of form called nested form.

Here is a reference for you about Nested form,.

like image 89
Thanh Avatar answered Oct 18 '22 18:10

Thanh