Phoenix

May 06, 2023

alias vs use vs. import

alias helps setup aliases for modules so you can use shorter names

alias FireStarter.Repo

import allows easy access to functions from other modules without using the fully qualified name

import Ecto.Query

def short_duration do
  from v in __MODULE__, where: v.duration < 800
end

use is similar to import but gives module authors more control over what is imported and allows injecting code

defmodule Firestarter.Video do
  use Ecto.Schema

  schema "videos" do
  end
end

General

IO.inspect() print output

list comprehension

for video <- @videos do

end

New

def new(conn, _) do
    changeset = change(%Event{})
    render conn, "new.html", changeset: changeset
end