Skip to content

Instantly share code, notes, and snippets.

@stevegraham
Last active September 6, 2015 20:32
Show Gist options
  • Save stevegraham/155f0966968796bda42e to your computer and use it in GitHub Desktop.
Save stevegraham/155f0966968796bda42e to your computer and use it in GitHub Desktop.
defmodule Teller.Web.SignupForm do
use Form,
email: :email,
password: :password,
password_confirmation: :password
validates :email, presence: true
validates :password, length: [min: 8], confirmation: true
end
defmodule Teller.Web.UserController do
use Teller.Web, :controller
alias Teller.User
plug :scrub_params, "user" when action in [:create, :update]
# ... snip
def create(conn, %{"user" => user_params}) do
case Teller.Web.SignupForm.save(%User{}, user_params) do
{:ok, _} ->
conn
|> put_flash(:info, "User created successfully.")
|> redirect(to: user_path(conn, :show))
{:error, form} ->
render(conn, "new.html", form: form)
end
end
# ... snip
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment