Building a Controller
You’ve already built a simple controller, so you know the drill. At this point, we could create all of the routes needed by a user automatically, but we’re going to play the boring community lifeguard that yells “Walk!” If you understand how a single route works, it’ll be much easier to explore the powerful shortcuts later. Specifically, we need two routes. UserController.index will show a list of users, and UserController.show will show a single user. As always, create the routes in router.ex:
| scope "/", Rumbl do |
| pipe_through :browser |
| get "/users", UserController, :index |
| get "/users/:id", UserController, :show |
| get "/", PageController, ... |
Get Programming Phoenix now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.