Skip to content

Instantly share code, notes, and snippets.

@PragTob

PragTob/changeset.ex

Last active Jul 24, 2017
Embed
What would you like to do?
small ecto changeset example
def new_changeset(model, params \\ %{}) do
model
|> cast(params, ~w(name username))
|> validate_required(~w(name username))
|> unique_constraint(:username)
|> validate_length(:username, min: 1, max: 20)
end
def registration_changeset(model, params) do
model
|> new_changeset(params)
|> cast(params, ~w(password))
|> validate_required(~w(password))
|> validate_length(:password, min: 6, max: 100)
|> put_pass_hash()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment