【问题标题】:undefined function: MyApp.Addict.Controller.init/1未定义函数:MyApp.Addict.Controller.init/1
【发布时间】:2015-10-02 08:01:07
【问题描述】:

我在 Phoenix:1.0.3 中使用 addict,我已按照 README 指南在我的应用程序中使用登录。调用登录时出现以下错误:

[error] #PID<0.2576.0> running MyApp.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /login
** (exit) an exception was raised:
** (UndefinedFunctionError) undefined function: MyApp.Addict.Controller.init/1 (module MyApp.Addict.Controller is not available)
MyApp.Addict.Controller.init(:login)
(my_app) web/router.ex:1: anonymous fn/1 in MyApp.Router.match/4
(my_app) lib/phoenix/router.ex:255: MyApp.Router.dispatch/2
(my_app) web/router.ex:1: MyApp.Router.do_call/2
(my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.phoenix_pipeline/1
(my_app) lib/plug/debugger.ex:90: MyApp.Endpoint."call (overridable 3)"/2
(my_app) lib/phoenix/endpoint/render_errors.ex:34: MyApp.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

【问题讨论】:

    标签: authentication elixir phoenix-framework


    【解决方案1】:

    这是由于我在router.ex 中的以下错误:

      scope "/", MyApp do
        addict :routes
      end
    

    这应该是:

      scope "/" do
        addict :routes
      end
    

    【讨论】:

    • 在我的情况下,情况正好相反:我忘了添加MyApp :) 无论如何,问题解决了。
    • 我在尝试使用OpenApiSpex.Plug.RenderSpec 时遇到了这个问题,它一直失败,并出现一个神秘的错误,说MyApp.OpenApiSpex.Plug.RenderSpec.init/1 不可用。我不得不删除, MyApp,它立即生效。
    【解决方案2】:

    在我的情况下,错误是通过运行解决的:

    $ mix deps.compile --force 
    

    产生错误的控制器已经存在了一段时间,并且有一个控制器测试没有报告任何错误。

    【讨论】:

    • 在我的情况下解决了它。当我进行一些繁重的 git 历史重写时,编译器可能会感到困惑。
    猜你喜欢
    • 2012-01-07
    • 2016-12-09
    • 2015-03-04
    • 2019-04-12
    • 2014-10-31
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多