Book Image

Phoenix Web Development

By : Brandon Richey
Book Image

Phoenix Web Development

By: Brandon Richey

Overview of this book

Phoenix is a modern web development framework that is used to build API’s and web applications. It is built on Elixir and runs on Erlang VM which makes it much faster than other options. With Elixir and Phoenix, you build your application the right way, ready to scale and ready for the increasing demands of real-time web applications. This book covers the basics of the Phoenix web framework, showing you how to build a community voting application, and is divided into three parts. In the first part, you will be introduced to Phoenix and Elixir and understand the core terminologies that are used to describe them. You will also learn to build controller pages, store and retrieve data, add users to your app pages and protect your database. In the second section you will be able to reinforce your knowledge of architecting real time applications in phoenix and not only debug these applications but also diagnose issues in them. In the third and final section you will have the complete understanding of deploying and running the phoenix application and should be comfortable to make your first application release By the end of this book, you'll have a strong grasp of all of the core fundamentals of the Phoenix framework, and will have built a full production-ready web application from scratch.
Table of Contents (14 chapters)
4
Introducing User Accounts and Sessions

Creating our Poll schema

A schema in Ecto needs one use statement and one import statement by default. In addition, we want to namespace the modules that we define for our new schema with the name of the app (but not the web app!) and the name of the context. We created votes as the subdirectory under the app "Vocial", so we'll create our module as Vocial.Votes.Poll. Next, we need to tell Ecto that this file will be using all of the Ecto functions and helpers that are available to us.

The schema will also be in charge of telling Ecto how to build changesets to modify data in our database, so we'll need to include that functionality via an import statement. We’ll also want to make our lives easier by including an alias for our full module definition so that we can just say %Poll{} instead of %Vocial.Votes.Poll{}. So we’ll start off building our...