O'Reilly logo

Programming Phoenix by Jose Valim, Bruce Tate, Chris McCord

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

Building a Feature

Our first feature won’t be complicated. It’ll print a string when you load a specific URL. To build that feature, we’re going to use a small fraction of the files that mix phoenix.new created. Don’t worry. You’ll get a tour of the whole tree a little later. For now, everything we need is in the web subdirectory. We’ll edit router.ex to point a URL to our code. We’ll also add a controller to the web/controllers subdirectory, a view to web/views, and a template to web/templates.

First things first. We want to map requests coming in to a specific URL to the code that satisfies our request. We’ll tie a URL to a function on a controller, and that function to a view. You’ll do so in the routing layer, as you would for other web ...

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