Hi,
how can I make a single form, fill in several other tables?
For example.
I have a registration form with the following columns (user, email, password) of the user table.
I have another registration form with the following columns (city, state, zip …) of the clients table
I need to create a single form that I can insert in the table “user, clients”
Note:
In the user form, I registered city, state, zip code.
But when I’m going to save the user, it’s just insert the user, email, password.
Below is my user controller.
def new(conn, _params, user) do
changeset = Registro.change_user(%User{})
render(conn, "new.html", changeset: changeset, user: user)
end
def create(conn, %{"user" => user_params}, user) do
case Registro.create_user(user_params) do
{:ok, user} ->
conn
|> put_flash(:info, "Usuário #{user.username} criado com sucesso.")
|> redirect(to: user_path(conn, :show, user))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset, user: user)
end
end