Created
October 17, 2015 10:07
-
-
Save Hajto/132d3a9427ce0130d87e to your computer and use it in GitHub Desktop.
Elixir phoenix problem
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.MasterCatController do | |
use Hangman.Web, :controller | |
alias Hangman.MasterCat | |
def index(conn, _params) do | |
query = from p in MasterCat, | |
select: p | |
a = Repo.all(query) | |
render conn, "index.json", mastercats: a | |
end | |
def create(conn, %{ "mastercats" => params }) do | |
IO.inspect(params) | |
a = MasterCat.changeset(%MasterCat{},params) | |
Repo.insert(a) | |
text(conn, a.valid?) | |
end | |
end | |
defmodule Hangman.MasterCat do | |
use Hangman.Web, :model | |
schema "mastercats" do | |
field :name, :string | |
has_many :categories, Hangman.Category | |
end | |
@required_fields ~w(name ) | |
@optional_fields ~w() | |
def changeset(model, params \\ :empty) do | |
model | |
|> cast(params, @required_fields, @optional_fields) | |
end | |
end | |
defmodule Hangman.MasterCatView do | |
use Hangman.Web, :view | |
alias Hangman.MasterCat | |
def render("index.json", %{ "assigns" => params }) do | |
params | |
end | |
def render("index.json", params ) do | |
IO.inspect(params) | |
"co sie spierdolilo" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment