A method used when you want to create a new instance of a child model that belongs to the parent model. (Parent model and child model have association settings) An instance can be created with a value in the foreign key.
If you want to create a memo instance associated with a user
note.controller.rb
@note = current_user.notes.build(note_params) ##Parent model.Child model.Format as build
Contents of the generated comment instance
@note
id: nil,
title: "aaa",
user_id: 2,
category_id: 1,
explanation: "ppppp",
created_at: nil,
updated_at: nil
The user_id contains a value.
Recommended Posts