2
我想渲染我的錯誤觀點沒有佈局:無法使我的錯誤觀點,在鳳凰城/藥劑沒有佈局
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")
但它不工作並呈現我的主要應用程序模板。當我取消註釋第二部分的代碼並註釋掉第一部分代碼時,它會永久掛起,並且不會呈現任何內容。
此外,我希望能夠設置layout false
我ErrorView,因爲我不希望有打電話給put_layout(false)
從我所有的控制器中的每個動作。
'conn |> put_status(404)|> put_layout(false)|> render(MyApp.ErrorView,「404.html」)'? – Dogbert
@Dogbert,我會試試看。但我希望能夠將layout(false)放入我的** ErrorView **中,因爲我不想從每個操作調用'put_layout(false)'。我怎樣才能做到這一點? – Kooooro
@Dogbert,是的,它可以工作,但我想這樣做 - 「我希望能夠在我的ErrorView中放置佈局(false),因爲我不想從每個操作調用put_layout(false)。我怎樣才能做到這一點? '也。 – Kooooro