【问题标题】:Phoenix not loading View module凤凰没有加载视图模块
【发布时间】:2017-12-13 19:01:01
【问题描述】:

我有一个带有相应 SessionView 的 SessionController,并且在模板目录中我有一个带有“new.html.eex”文件的“会话”文件夹。当我导航到 session_path “新”操作时,我收到一个错误:

HelloWeb.SessionView 不可用

它看起来像是在调用SessionView.render/2

在 session_controller 中,我只是尝试渲染 new.html.eex,这是新的操作:

def new(conn, _params) do
  render conn, "new.html"
end

Phoenix 应该正在渲染“新”模板,但错误不断出现,我不知道为什么。一切都拼写正确,我在“router.ex”文件中正确映射了路线。

## Routes for sessions ##
get    "/login",  SessionController, :new
post   "/login",  SessionController, :create
delete "/logout", SessionController, :delete

但是,调用“登录”会产生错误

SessionView.render/2 未定义(模块 HelloWeb.SessionView 不可用)。

是什么导致 Phoenix 无法加载“新”模板?

更新:这是 session_view:

defmodule Gofish.SessionView do
  use GofishWeb, :view
end

【问题讨论】:

  • 您能否展示一下您的会话视图模块的内容?

标签: session authentication elixir phoenix-framework


【解决方案1】:

您需要在lib/hello_web/views 目录上创建一个session_view.ex

它的最小内容是:

defmodule HelloWeb.SessionView do
  use HelloWeb, :view
end

【讨论】:

  • 是的,我有一个包含基本内容的会话视图。这就是为什么我对它为什么不起作用感到困惑的原因。我拥有呈现 new.html.eex 模板所需的所有组件,但它仍然会引发错误。 defmodule Gofish.SessionView 使用 GofishWeb, :view end
  • Frederick,你能把你的整个源代码树放到 Github 或其他地方吗?
  • 您应该将session_view.ex 的第一行从defmodule Gofish.SessionView do 更改为defmodule GofishWeb.SessionView do
  • 我非常肯定凤凰的问题;我不敢相信我忽略了这个错字很多次却没有注意到它!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-02
  • 2017-07-21
  • 1970-01-01
相关资源
最近更新 更多