October 2019
Intermediate to advanced
358 pages
8h 22m
English
We have a form that submits the data for a new user. It’s time to surface this new feature in our controller. This work should happen in our context. Let’s extend Accounts to create users. Open up lib/rumbl/accounts.ex and key this in:
| | def create_user(attrs \\ %{}) do |
| | %User{} |
| | |> User.changeset(attrs) |
| | |> Repo.insert() |
| | end |
Take a look at the new short create_user function. We save our controller from this tiny bit of complexity. Our function has a short pipeline that starts with an empty user, applies a changeset, and then inserts it into the repository. The controller shouldn’t care about these short persistence details, but neither should the schema. We isolate ...
Read now
Unlock full access