Skip to content

Instantly share code, notes, and snippets.

@PragTob
Last active July 24, 2017 20:44
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 PragTob/797c4e49489450e2d5d391607f0c70b6 to your computer and use it in GitHub Desktop.
Save PragTob/797c4e49489450e2d5d391607f0c70b6 to your computer and use it in GitHub Desktop.
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