The Pragmatic Studio

Create the App

Notes & Exercises

Code Snapshot

A snapshot of the code at the end of the video is in the raffley/02-create-app directory of the code bundle.

Generator Help

To see all the options supported by the Phoenix application generator, run:

mix phx.new

Exclude Directories From VS Code

If you'd like to exclude the _build and deps directories from appearing in your VS Code Explorer, use the following VS Code settings:

"files.exclude": {
  "**/_build": true,
  "**/deps": true
}

Getting a Database Error?

If you see a database-related error when running mix ecto.create, it's likely a Postgres connection issue.

First check the database username and password values at the top of config/dev.exs. By default, Phoenix assumes that your PostgreSQL installation has a user named postgres with a password of postgres. If your setup is different, you'll need to adjust the database configuration in the config/dev.exs file.

Second, installing PostgreSQL typically starts the PostgreSQL server daemon. However, depending on your operating system, you may need to start the server daemon manually. To do that, you may find the first steps or Archlinux wikis helpful.

Exercise

To lock in what you learned in the videos, in the exercises you'll incrementally build a different Phoenix app with similar features for responding to real-time incidents around your neighborhood or community. You know, urgent things like a lost dog, a driver with a flat tire, or a neighbor in need. It'll be similar enough to the raffles application as to not be too challenging, but different enough to still tickle your brain. 🤔

In this first exercise, we'll get the incident management app up and running:

  1. Create a new Phoenix app named heads_up:

    mix phx.new heads_up

    When prompted to fetch and install dependencies, answer Y.

  2. Then change into the generated heads_up directory and create the development database using the default database configuration:

    cd heads_up
    
    mix ecto.create
  3. Go ahead and copy in some CSS and images we've already cooked up that you'll use later on.

    To do that, locate the prepared-files/heads_up directory of the code bundle. In that directory you'll see an app.css file. Copy it into the heads_up application's assets/css directory, overwriting the existing app.css file. Also copy all the prepared images files in the images directory to the heads_up application's priv/static/images directory.

  4. Fire up the Phoenix server:

    mix phx.server
  5. Browse to http://localhost:4000 and you should see the Phoenix welcome page!

  6. Finally, open the heads_up directory in your favorite editor and take a quick peek at the generated directories. Initially it may seem overwhelming, but don't sweat it: over time it will feel more and more like home. 🏠

Solution

The solution for the exercise is in the heads_up/02-create-app directory of the code bundle.

How's Your Elixir Game?

If you're new to the Elixir programming language, learning Phoenix might feel like someone tied your shoelaces together and asked you play some hoops. 🏀 🤕

Imagine knowing Elixir so well you can drive to the basket and dunk! ⛹🏻 That's what you'll be able to do after taking our Elixir & OTP course. So before getting too far into Phoenix, we highly recommend joining us in the Elixir course to gain clarity and confidence with the language.

elixir

We start with the Elixir fundamentals and leave no stone unturned as we build a simple web server step-by-step from scratch. And the second half of the course is all about OTP, so it's like getting two courses in one. 🙌

We think you're gonna love it!

All course material, including videos and source code, is copyrighted and licensed for individual use only. You may make copies for your own personal use (e.g. on your laptop, on your iPad, on your backup drive). However, you may not transfer ownership or share the material with other people. We make no guarantees that the source code is fit for any purpose. Course material may not be used to create training material, courses, books, and the like. Please support us by encouraging others to purchase their own copies. Thank you!

Copyright © 2005–2024, The Pragmatic Studio. All Rights Reserved.

Full-Stack Phoenix

0% complete
To Be Released Soon...
  • Async Data Fetching
  • Admin Table UI
  • New Raffle Form
  • Create Raffle
  • Ecto Changesets
  • Forms With Changesets
  • Live Form Validations