ecallen

Commands

curl api.ipify.org - return external ip address

Elixir

self()

spawn_link(self(), fn -> raise “oops” end)

spawn(…)

send(pid, {:get, :hello, self()})

flush()

{:ok, pid} = Agent.start_link(fn -> %{} end)

Agent.update(pid, fn map -> Map.put(map, :hello, :world) end)

Agent.get(pid, fn map -> Map.get(map, :hello) end)

opts \ [] - optional parameter that will default to empty list

Phoenix - Elixir

Recreate the env

mix phx.new statmeet

cd statmeet

edit config/dev.exs

mix deps.get

mix ecto.create

mix phx.gen.auth Accounts User users

mix phx.gen.html Markups Note notes contents:text

Adding a new page

Example of adding Hello page

Create the route

lib//router.ex


scope "/", AppWeb do
...

get "/somepath", HelloController, :index

end

Add a new controller

lib/_web/controllers/_controller.ex


defmodule HelloWeb.HelloController do
  use HelloWeb, :controller

  def index(conn, _params) do
    render(conn, "index.html")
  end
end

Add a view

lib/_web/views/_view.ex


defmodule HelloWeb.HelloView do
  use HelloWeb, :view
end

Add a template

lib/_web/templates//index.html.heex


<section class="phx-hero">
  <h2>Hello World, from Phoenix!</h2>
</section>

Adding a new schema

mix phx.gen.schema Markups markups content:text

Adding forms/context

mix phx.gen.html Catalog Product products title:string description:string price:decimal views:integer

Update a model

mix ecto.gen.migration update_notes

edit file in priv/repo/migrations/

mix ecto.migrate




Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.