I've installed phoenix JSON package through mix phoenix.gen.json V1.Post posts title:string content:string secret:string --no-model
but got this error:
== Compilation error on file web/controllers/v1/post_controller.ex ==
** (CompileError) web/controllers/v1/post_controller.ex:14: Shopper.V1.Post.__struct__/0 is undefined, cannot expand struct Shopper.V1.Post
(elixir) src/elixir_map.erl:55: :elixir_map.translate_struct/4
(stdlib) lists.erl:1353: :lists.mapfoldl/3
(elixir) src/elixir_clauses.erl:36: :elixir_clauses.clause/7
(elixir) src/elixir_def.erl:178: :elixir_def.translate_clause/7
(elixir) src/elixir_def.erl:167: :elixir_def.translate_definition/8
(elixir) src/elixir_def.erl:82: :elixir_def.store_definition/9
web/controllers/v1/post_controller.ex:13: (module)
(stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
here is my router.ex code:
defmodule Shopper.Router do
use Shopper.Web, :router
pipeline :api do
plug :accepts, ["json"]
end
scope "/", Shopper do
pipe_through :api
resources "/v1/posts", V1.PostController
end
end
From the documentation said:
Add the resource to the proper scope in web/router.ex:
resources "/posts", PostController
But.. I can't make it work, could anybody help me? Thank you.
Please note that this is for phoenix 1.0 and elixir 1.0.
--no-modelis useful when the model already exists and you just want to re-use it. - José Valim