Showing a User

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 lib/rumbl_web/controllers/user_controller.ex:

Get Programming Phoenix 1.4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.