编程Phoenix:未定义的函数page_path / 2

时间:2016-11-06 12:07:09

标签: elixir phoenix-framework

我的网络应用程序出现问题,编译错误如下:

$("path:not(.active)").unbind('mouseenter mouseleave')

我知道大多数问题都与== Compilation error on file web/controllers/auth.ex == ** (CompileError) web/controllers/auth.ex:49: undefined function page_path/2 (stdlib) lists.erl:1338: :lists.foreach/2 (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6 (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1 上缺少的路线有关,但它看起来没有任何问题:

router.ex

我的web.ex看起来像这样:

  scope "/", Rumbl do
    pipe_through :browser # Use the default browser stack

    get "/", PageController, :index
    get "/users/:id", UserController, :show
    resources "/users", UserController, only: [:index, :show, :new, :create]
    resources "/sessions", SessionController, only: [:new, :create, :delete]
    resources "/videos", VideoController

  end

  scope "/manage", Rumbl do
    pipe_through [:browser, :authenticate_user]

    resources "/videos", VideoController
  end

auth.ex看起来像这样

def router do
  quote do
    use Phoenix.Router
    import Rumbl.Auth, only: [authenticate_user: 2] # New import
  end
end

def controller do
  quote do
    use Phoenix.Controller

    alias Rumbl.Repo
    import Ecto
    import Ecto.Query, only: [from: 1, from: 2]

    import Rumbl.Router.Helpers
    import Rumbl.Gettext
    import Rumbl.Auth, only: [authenticate_user: 2] # New import

  end
end

2 个答案:

答案 0 :(得分:11)

你可以发布auth.ex文件吗?似乎第49行有一个问题。

解决方案:

请更改此行:

|> redirect(to: page_path(conn, :index))

|> redirect(to: Helpers.page_path(conn, :index))

答案 1 :(得分:2)

在phoenix 1.4中,您需要使用模块名称调用该函数

Routes.page_path(@conn, :create)