October 2019
Intermediate to advanced
358 pages
8h 22m
English
Now that we have a database-backed context, let’s add the ability to create new users in our system. We’re going to use Phoenix’s form builders for that purpose. First, open up your controller at lib/rumbl_web/controllers/user_controller.ex and set up a new user account struct for our new template, like this:
| | alias Rumbl.Accounts.User |
| | |
| | def new(conn, _params) do |
| | changeset = Accounts.change_user(%User{}) |
| | render(conn, "new.html", changeset: changeset) |
| | end |
Notice the Accounts.change_user function. This function receives a struct, and returns an Ecto.Changeset. Changesets let Ecto manage record changes, cast parameters, and perform validations. ...
Read now
Unlock full access