Skip to content

Instantly share code, notes, and snippets.

@umuro
Last active September 2, 2017 01:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save umuro/4af1324602b36ca92394f4bd8b41f8f5 to your computer and use it in GitHub Desktop.
Save umuro/4af1324602b36ca92394f4bd8b41f8f5 to your computer and use it in GitHub Desktop.
Elixir Cheatsheets

Preperation

Installation

sudo apt-get install inotify-tools #ubuntu
sudo apt-get install postgresql #Ubuntu

mix local.hex #install hex
mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez #phoenix archive

Create Project

mix phoenix.new hello_phoenix
cd  hello_phoenix

Setup Project Databse

#configure your database in config/dev.exs
mix ecto.create

Running

Run Project

mix phoenix.server #Run Application
iex -S mix phoenix.server #Run Interactive Elixir
iex -S mix
mix compile #Compile all

Access Project

http://localhost:4000

Development

  • web/router.ex
    • get "/hello", HelloController, :index
    • resources "/users", UserController
  • web/controllers/hello_controller.ex #controller
  • web/views/hello_view.ex #view
  • web/templates/hello/index.html.eex #template
  • web/views/layout_view.ex #layout
mix phoenix.routes

Adding Models

  • phoenix.gen.json {params} or phoenix.gen.json {params}
  • mix ecto.migrate
mix test

iex -S mix test --trace
#require IEx
#IEx.pry
#IO.puts foo

Mix Tasks

Phoenix

$ mix help | grep -i phoenix
mix phoenix.digest      # Digests and compress static files
mix phoenix.gen.channel # Generates a Phoenix channel
mix phoenix.gen.html    # Generates controller, model and views for an HTML based resource
mix phoenix.gen.json    # Generates a controller and model for a JSON based resource
mix phoenix.gen.model   # Generates an Ecto model
mix phoenix.new         # Create a new Phoenix v1.1.2 application
mix phoenix.routes      # Prints all routes
mix phoenix.server      # Starts applications and their servers

Ecto

$ mix help | grep -i ecto
mix ecto.create          # Create the storage for the repo
mix ecto.drop            # Drop the storage for the repo
mix ecto.gen.migration   # Generate a new migration for the repo
mix ecto.gen.repo        # Generates a new repository
mix ecto.migrate         # Runs migrations up on a repo
mix ecto.rollback        # Reverts migrations down on a repo
mix run priv/repo/seeds.exs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment