【发布时间】:2018-08-11 12:59:58
【问题描述】:
刚开始使用 Phoenix,我生成了项目并运行了 phoenix.gen.json Todo todos description:string
/lib/test_web/router.ex
# Other scopes may use custom stacks.
scope "/api", TestWeb do
pipe_through :api
resources "/todos", TodoController, except: [:new, :edit]
end
/web/controllers/todo_controller.ex
defmodule Test.TodoController do
use Test.Web, :controller
alias Test.Todo
def index(conn, _params) do
todos = Repo.all(Todo)
render(conn, "index.json", todos: todos)
end
end
对 /api/todos 的 GET 给出 500 - ** (UndefinedFunctionError) 函数 TestWeb.TodoController.init/1 未定义(模块 TestWeb.TodoController 不可用)
【问题讨论】:
-
控制器模块不应该命名为
TestWeb.TodoController吗? -
@mudasobwa 同样的错误
-
您已经在路由器中明确限制
POST使用此网址,您为什么期望它可以工作? -
@mudasobwa GET 不起作用,因为控制器未定义
-
如何运行应用程序?