- Install the following in
assets
:
npm install --save bootstrap jquery popper.js
npm install --save-dev [email protected] node-sass
- Rename
assets/app.css
toassets/app.scss
- Edit
webpack.config.js
to addsass-loader
and enablescss
compilation:
defmodule ExBs.Components.Form do | |
@moduledoc """ | |
Helpers for building Phoenix forms with Bootstrap components. | |
""" | |
import ExBs.Config, only: [translation_fn: 0] | |
import ExBs.Components.Form.Input, only: [input: 3] | |
alias Phoenix.HTML.{Form, Tag} |
assets
:npm install --save bootstrap jquery popper.js
npm install --save-dev [email protected] node-sass
assets/app.css
to assets/app.scss
webpack.config.js
to add sass-loader
and enable scss
compilation:Estrutura anterior:
/
+ I001
+ new
+ processed
+ I002
+ new
+ processed
var _pc_resizeIFrame = function(iframe) { | |
iframe.height = iframe.contentDocument.body.scrollHeight; | |
} | |
document.querySelectorAll(".pc-iframe").forEach(function(iframe) { | |
window.onload = function () { | |
_pc_resizeIFrame(iframe); | |
}; | |
window.onresize = function () { | |
_pc_resizeIFrame(iframe); |
defmodule App.Membership do | |
# ... | |
def changeset(struct, params \\ %{}) do | |
struct | |
# ... | |
|> put_role | |
|> cast_assoc(:user, required: true) | |
end | |
defp put_role(changeset) do |
defmodule App.Membership do | |
schema "memberships" do | |
field :role | |
end | |
end |
defmodule App.Account do | |
# ... | |
def changeset(struct, params \\ %{}) do | |
struct | |
# ... | |
|> cast_assoc(:memberships, required: true) | |
end | |
end | |
defmodule App.Membership do | |
# ... |
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} |
<%= 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"> |
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 |