Created
November 21, 2016 19:29
-
-
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
This file contains 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
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