Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active August 18, 2017 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/e0379f63de933cd4ee8bbe8dab80ec38 to your computer and use it in GitHub Desktop.
Save shankardevy/e0379f63de933cd4ee8bbe8dab80ec38 to your computer and use it in GitHub Desktop.
defmodule MangoWeb.RegistrationController do
use MangoWeb, :controller
alias Mango.CRM
def new(conn, _) do
changeset = CRM.build_customer()
residence_areas = Auroville.ResidenceService.list_areas
render(conn, "new.html", changeset: changeset, residence_areas: residence_areas)
end
def create(conn, %{"registration" => registration_params}) do
case CRM.create_customer(registration_params) do
{:ok, _customer} ->
conn
|> put_flash(:info, "Registration successful")
|> redirect(to: page_path(conn, :index))
{:error, changeset} ->
residence_areas = Auroville.ResidenceService.list_areas
conn
|> render(:new, changeset: changeset, residence_areas: residence_areas)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment