Skip to content

Instantly share code, notes, and snippets.

@chrismcg
Created August 2, 2015 11:34
Show Gist options
  • Save chrismcg/75fb6159286f3758dbc0 to your computer and use it in GitHub Desktop.
Save chrismcg/75fb6159286f3758dbc0 to your computer and use it in GitHub Desktop.
Example Phoenix / Ecto Form Model
defmodule Phlink.Form do
use Ecto.Schema
import Ecto.Changeset
@primary_key false
schema "non_db_form.user" do
field :name, :string
field :thing, :string
end
@required_fields ~w(name)
@optional_fields ~w(thing)
def changeset(model, params \\ :empty) do
cast(model, params, @required_fields, @optional_fields)
|> validate_length(:name, min: 3)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment