Building the poll controller

Okay, so now that we're rocking a very thorough understanding of the connection flow and how Phoenix is handling each step along the way, let's start building our own controllers, views, routes, and templates to display something when a user goes to /polls in the browser. We'll start off by creating a new file, lib/vocial_web/controllers/poll_controller.ex. Much like our page controller, we're going to give this file a really basic structure:

defmodule VocialWeb.PollController do use VocialWeb, :controller def index(conn, _params) do   render conn, "index.html" endend

Next, remember that every controller and function inside of a controller should have corresponding views and templates. Let's create lib/vocial_web/views/poll_view.ex ...

Get Phoenix Web Development 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.