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

Creating the new action in the controller

Right now, those routes won't work, because they don't yet have a controller action associated with them. Let's hop into our poll_controller.ex file and create the new action:

def new(conn, _params) do   poll = Vocial.Votes.new_poll()      conn   |> put_layout("special.html")   |> render "new.html", poll: poll end

First, we start off by creating a new blank poll object. We'll use a function in our context that doesn't actually exist yet. We want to keep our context as the main method of interaction between our controller and our database, so we'll just pick a function name and use that later. Next, we'll basically just copy our index function over from the controller and use that code.

One thing you might notice ...

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