Created
December 31, 2017 02:52
-
-
Save elderbas/f28a3a530df7a232c359b8f514d6d394 to your computer and use it in GitHub Desktop.
Inserting Multiple Changesets Into Database - create controller example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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