Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Phoenix Part I

Jessica Goulding
November 07, 2016
30

Intro to Phoenix Part I

Getting started with Phoenix projects and Elixir

Jessica Goulding

November 07, 2016
Tweet

Transcript

  1. SET UP ▸ Assuming install of Elixir & Erlang ▸

    Database installed (postgres or mysql) ▸ Install dependencies for Phoenix ▸ Phoenix Docs: http://www.phoenixframework.org/docs/ installation ▸ Let’s build! requirements and resources versions, latest vs .10 etc $ mix local.hex $ mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez
  2. CREATE ▸ create db and user ▸ mix phoenix.new {project_name}

    ▸ to use your app for API purposes only, pass in —no-html flag ▸ edit config with db username and password ▸ mix ecto.create ▸ mix phoenix.server createdb meetup_example createuser ecto —pwprompt make sure we can login with that user psql meetup_example --user ecto explicit path vs in your directory edit with db info we use the ecto.create to compile run server
  3. OUT OF THE BOX ▸ Routes ▸ mix phoenix.routes ▸

    Controllers ▸ Views ▸ Tests ▸ mix test Let’s take a look at what we get with our routes, our basic gets scoped through our index and an api pipeline. First time we run our tests, we compile these files, we should see an error because we haven’t set up our test repo. createdb {db test name} remove username and password config/test.exs check out the basic test infrastructure we get, so awesome!
  4. GENERATED VS MANUAL ▸ Generators take arguments for creation {Class

    Name} {db_table_name} {table_options} ▸ mix phoenix.gen.html ▸ mix phoenix.gen.json We can manually add controllers and actions associated, from our command line or we can use these generators and they give us a LOT
  5. TESTING ▸ Ex_Machina ▸ Single Factory File ▸ https://github.com/thoughtbot/ex_machina ▸

    Pry ▸ iex -S mix test ▸ require IEx && place in file IEx.pry We use ex_machina to create some factory data structures we have access to pry and allowing us to stop our server and debug
  6. NEXT MEETUP… ▸ Exploring Channels ▸ Idea: ▸ Building a

    retro doc webpage ▸ View real-time posts from multiple users ▸ Authentication/Login ▸ Capturing posts and usernames associated