April 2016
Beginner to intermediate
300 pages
6h 58m
English
Now that we’ve created the code to show a list of users, we can work on showing a single user. To refresh your memory, let’s look at the route we created earlier:
| | get "/users/:id", UserController, :show |
That’s easy enough. On a request to /users/:id, where :id is part of the inbound URL, the router will add at least two things we’ll need to conn, including the :id that’s part of the URL, and the action name, :show. Then, the router will call the plugs in our pipeline, and then the UserController. To show a single user using this request, we need a controller action, which we add to web/controllers/user_controller.ex:
| | def show(conn, ... |