# in a controller
def test1(conn, params) do
case Repo.get_by(MyModel, title: params["title"]) do
nil ->
put_status(conn, 403)
|> put_layout(false)
|> render(MyAppWeb.ErrorView, "404.html")
# in the config:
debug_errors: false,
Output:
Internal server error
Why? No idea.
And a 2nd question: How can render an error html template with no layout without having to say put_layout(false) from a controller? Namely, I want to set “nil” layout from within ErrorView.
You can build your own render error function if You want to dry your code.
def test1(conn, params) do
case Repo.get_by(MyModel, title: params["title"]) do
nil -> render_error(conn)
...
defp render_error(conn) do
conn
|> put_status(403)
|> put_layout(false)
|> render(MyAppWeb.ErrorView, "404.html")
end
How can render an error html template with no layout without having to say put_layout(false) from a controller? Namely, I want to set “nil” layout from within ErrorView.