Skip to content

Instantly share code, notes, and snippets.

@Hajto
Created October 17, 2015 12:12
Show Gist options
  • Save Hajto/9fc5c30d0f857881f11d to your computer and use it in GitHub Desktop.
Save Hajto/9fc5c30d0f857881f11d to your computer and use it in GitHub Desktop.
123
defmodule Hangman.CategoryController do
use Hangman.Web, :controller
alias Hangman.Category
def create(conn, %{ "category" => params }) do
IO.inspect(params)
a = Category.changeset(%Category{},params)
Repo.insert(a)
text(conn, a.valid?)
end
end
defmodule Hangman.Category do
use Hangman.Web, :model
schema "categories" do
field :name, :string
has_many :words, Hangman.Word
belongs_to :mastercat, Hangman.MasterCat
end
@required_fields ~w(name)
@optional_fields ~w()
def changeset(model, params \\ :empty) do
model
|> cast(params, @required_fields, @optional_fields)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment