Skip to content

Instantly share code, notes, and snippets.

@elderbas
Created December 31, 2017 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elderbas/f28a3a530df7a232c359b8f514d6d394 to your computer and use it in GitHub Desktop.
Save elderbas/f28a3a530df7a232c359b8f514d6d394 to your computer and use it in GitHub Desktop.
Inserting Multiple Changesets Into Database - create controller example
...
def create(conn, %{"person" => params}) do
changeset = Person.changeset(%Person{}, class_params)
case Repo.insert(changeset) do
{:ok, person} ->
conn
|> put_status(:created)
|> render("show.json", person: person)
{:error, _, changeset, _} ->
conn
|> put_status(:unprocessable_entity)
|> render(MyApp.ChangesetView, "error.json", changeset: changeset)
end
end
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment