- 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
defmodule App.Membership do | |
schema "memberships" do | |
field :role | |
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 App.Account do | |
# ... | |
def changeset(struct, params \\ %{}) do | |
struct | |
# ... | |
|> cast_assoc(:memberships, required: true) | |
end | |
end | |
defmodule App.Membership 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 Class.RegistrationController do | |
# ... | |
def create(conn, %{"account" => params}) do | |
changeset = Account.changeset(%Account{}, params) | |
case Repo.insert(changeset) do | |
{:ok, account} -> | |
redirect conn, to: registration_path(conn, :new) | |
{:error, changeset} -> | |
changeset = %{changeset | action: :insert} |
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, :name %> | |
<%= text_input f, :name, class: "form-control" %> | |
<%= error_tag f, :name %> | |
</div> | |
<div class="form-group"> | |
<%= inputs_for f, :memberships, fn mf -> %> | |
<%= inputs_for mf, :user, fn uf -> %> | |
<div class="form-group"> |
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 | |
# ... | |
def new(conn, _params) do | |
changeset = | |
Account.changeset( | |
%Account{memberships: [ | |
%Membership{user: %User{}}]}) | |
render conn, "new.html", changeset: changeset | |
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
%{"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
<%= 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 |