April 2016
Beginner to intermediate
300 pages
6h 58m
English
Recall our changes to the router.ex file, when we added the resources "/users" macro to router.ex to build a set of conventional routes. One new route maps posts to "/users" to the UserController.create action. Add a create function to UserController:
| | def create(conn, %{"user" => user_params}) do |
| | changeset = User.changeset(%User{}, user_params) |
| | {:ok, user} = Repo.insert(changeset) |
| | |
| | conn |
| | |> put_flash(:info, "#{user.name} created!") |
| | |> redirect(to: user_path(conn, :index)) |
| | end |
This pattern of code should be getting familiar to you by now. We keep piping functions together until the conn has the final result that we want. Each ...