Skip to content

Instantly share code, notes, and snippets.

@elderbas
Created December 31, 2017 02:37
Show Gist options
  • Save elderbas/10e8ae6873bb9b0b52eeb489da2e4f42 to your computer and use it in GitHub Desktop.
Save elderbas/10e8ae6873bb9b0b52eeb489da2e4f42 to your computer and use it in GitHub Desktop.
Person module
defmodule MyApp.Person do
use MyApp.Web, :model
schema "people" do
field :name, :string
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:name])
|> validate_required([:name])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment