Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content