Created
August 2, 2015 11:34
-
-
Save chrismcg/75fb6159286f3758dbc0 to your computer and use it in GitHub Desktop.
Example Phoenix / Ecto Form Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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