Skip to content

Instantly share code, notes, and snippets.

@abitdodgy
Created November 21, 2016 19:29
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 abitdodgy/ccb25e89c9ef8cf189c3fedb9bb86162 to your computer and use it in GitHub Desktop.
Save abitdodgy/ccb25e89c9ef8cf189c3fedb9bb86162 to your computer and use it in GitHub Desktop.
Medium Article: Medium Article: Building Many-to-Many Associations with cast_assoc and Nested Forms in Phoenix and Ecto
defmodule Class.RegistrationController do
# ...
def create(conn, %{"account" => params}) do
changeset = Account.changeset(%Account{}, params)
case Repo.insert(changeset) do
{:ok, account} ->
redirect conn, to: registration_path(conn, :new)
{:error, changeset} ->
changeset = %{changeset | action: :insert}
render conn, "new.html", changeset: changeset
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment