Created
October 17, 2015 12:12
-
-
Save Hajto/9fc5c30d0f857881f11d to your computer and use it in GitHub Desktop.
123
This file contains hidden or 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 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