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

Connecting polls to users

As mentioned previously, we did a lot of work when setting up user accounts in our system but nothing to actually connect, or even restrict access to, polls and user accounts. Thinking back to how we've set up other associations, there are a couple of steps that we have to implement before all of our polls are correctly linked to users. They are as follows:

  1. We need to link our tables by creating a migration that adds user_id to our polls table.
  2. We then need to modify the code in our schemas to represent the addition of the association.
  3. We need to modify all of the creation code in the context to set the poll's user_id to the appropriate user.
  4. Finally, we need to modify all of the delete and update code to only allow those functions to happen if the current user is the owner of that poll.
...