【发布时间】:2016-11-27 05:38:43
【问题描述】:
我想在没有布局的情况下呈现我的错误视图:
defmodule MyApp.ErrorView do
use MyApp.Web, :view
def render("404.html", assigns) do # renders my_404.html.eex template
render(__MODULE__, "my_404.html")
end
和行动:
def my_action(conn) do
if something_wrong do
conn
|> put_status(404)
|> render(MyApp.ErrorView, "404.html")
# conn
# |> put_status(404)
# |> put_layout(false)
# |> put_view(MyApp.ErrorView)
# |> render("404.html")
但它不起作用,它会呈现我的主应用程序模板。当我取消注释我的代码的第二部分并注释掉第一部分时,它将永远挂起并且不会呈现任何内容。
我还希望能够在我的 ErrorView 中设置layout false,因为我不想在所有控制器的每个操作中都调用put_layout(false)。
【问题讨论】:
-
conn |> put_status(404) |> put_layout(false) |> render(MyApp.ErrorView, "404.html")? -
@Dogbert,我会试试的。但我希望能够将布局 (false) 放入我的 ErrorView 中,因为我不想从每个操作中调用
put_layout(false)。我该怎么做? -
@Dogbert,是的,它有效,但我也想要这个——
I want to be able to put layout (false) in my ErrorView, because I don't want to call put_layout(false) from each action. How can I do that?。