April 2016
Beginner to intermediate
300 pages
6h 58m
English
The create action in the UserController must now use our new registration_changeset, like this:
| | def create(conn, %{"user" => user_params}) do |
| | changeset = User.registration_changeset(%User{}, user_params) |
| | case Repo.insert(changeset) do |
| | {:ok, user} -> |
| | conn |
| | |> put_flash(:info, "#{user.name} created!") |
| | |> redirect(to: user_path(conn, :index)) |
| | {:error, changeset} -> |
| | render(conn, "new.html", changeset: changeset) |
| | end |
| | end |
We use pattern matching to pick off the user_params from the inbound form. We create a registration changeset, and if it’s valid, we insert it and present the result to the user. If not, ...
Read now
Unlock full access