- install npm packages
- update brunch-config.js
- rename web/static/css/app.css to web/static/css/app.scss
- update web/static/css/app.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{"account" => %{ | |
"name" => "Ecto Phoenix Demo", | |
"memberships" => %{ | |
"0" => %{ | |
"user" => %{ | |
"email" => "mohamad@example.com"}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule App.Account do | |
schema "accounts" do | |
field :name, :string | |
has_many :memberships, App.Membership | |
has_many :users, through: [:memberships, :user] | |
end | |
def changeset(struct, params \\ %{}) do | |
struct | |
|> cast(params, [:name]) | |
|> validate_required([:name]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule App.RegistrationController do | |
use App.Web, :controller | |
alias App.{Registration, Repo} | |
def new(conn, _params) do | |
changeset = Registration.changeset(%Registration{}) | |
render conn, :new, changeset: changeset | |
end | |
def create(conn, %{"registration" => registration_params}) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule App.Registration do | |
use App.Web, :model | |
alias App.{Account, User, Membership, Repo} | |
embedded_schema do | |
field :email | |
field :org_name | |
end | |
@required_fields ~w(email org_name)a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @changeset, registration_path(@conn, :create), fn f -> %> | |
<div class="form-group"> | |
<%= label f, :org_name %> | |
<%= text_input f, :org_name, class: "form-control" %> | |
<%= error_tag f, :org_name %> | |
</div> | |
<div class="form-group"> | |
<%= label f, :email %> | |
<%= text_input f, :email, class: "form-control" %> | |
<%= error_tag f, :email %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Event.Plug.API.VersionRouter do | |
@default_api_version "1" | |
def init(options) do | |
case Keyword.fetch!(options, :versions) do | |
versions -> | |
for {version, router} <- versions, into: %{} do | |
{version, {router, router.init([])}} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Event.Plug.API.VersionRouter do | |
import Plug.Conn | |
@default_version 1 | |
def init(options) do | |
case Keyword.fetch!(options, :versions) do | |
versions -> | |
for {version, router} <- versions, into: %{} do | |
{version, {router, router.init([])}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Event.Plug.API.VersionRouter do | |
import Plug.Conn | |
@default_version 1 | |
def init(options) do | |
for {version, router} <- options, into: %{} do | |
{version, {router, router.init([])}} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 2 - REVERSAL | |
# | |
# The quickest way to reverse an array is to swap elements at either end, and repeat | |
# while moving up from the left and down from the right. | |
# | |
# [ a b c d e f ] | |
# [ f a ] - Step 1 we switched A[0] with A[-1] | |
# [ e b ] - Step 2 we switched A[1] with A[-2] | |
# [ d c ] - Step 3 we switched A[2] with A[-3] |