O'Reilly logo

Elixir Cookbook by Paulo A Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a controller

In Phoenix, controllers are Elixir modules that define functions (or actions) to handle the requests dispatched by the router. The controllers are responsible for preparing and passing data to the view layer and determining the rendering of these views.

Getting ready

To get started, we will extend the project defined in the Defining routes recipe. The defined routes are as follows:

 page_path  GET     /                Todo.PageController.index/2
   my_path  GET     /text            Todo.MyController.plaintext/2
   my_path  GET     /generated       Todo.MyController.send_html/2
todos_path  GET     /todos           Todo.TodosController.index/2
todos_path  GET     /todos/:id/edit  Todo.TodosController.edit/2
todos_path  GET     /todos/new       Todo.TodosController.new/2
todos_path GET /todos/:id Todo.TodosController.show/2 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required