Search code examples
ruby-on-railsrubyscaffolding

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?


Solution

  • 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,.