Building Controllers, Views, and Templates
This chapter is focused on the building blocks of any Phoenix application. By understanding what controllers, views, and templates are (and how they interact), it becomes much easier to build out our web application. We'll tackle this through the perspective of building the first major component of our Live Voting application, and by writing tests to cover the new functionality introduced.
The reader will become proficient in a lot of the basic tenets of using controllers, views, and templates. In addition, the reader will learn how the three pieces fit together via functional composition. Finally, they'll begin diving into writing their first tests covering controllers and views to start enforcing a strong and real-world systems development life cycle (SDLC). This will be from the perspective of building an actual application, so we'll start laying the framework for our voting app.
We've stepped through the very basics of creating a sample application and learned a little bit about the base structure of Elixir and how to use a few of the helper tools such as IEx, and also talked about what the structure of a Phoenix application will be, but now we actually need to start diving into the code itself and start understanding each of the pieces of our application. In my mind, the controllers are one of the most important pieces of a Phoenix application, as they provide that all-important bridge between what your database holds, what your schemas interpret, and what the user actually sees on their screen (whether it’s via API calls or browser requests).