@bennelsonweiss explained it perfectly.
- They use
withbecause they want to handle those errors by matching on them inaction_fallbacklike:
def call(conn, {:error, %Ecto.Changeset{} = changeset}) do
conn
|> put_status(:unprocessable_entity)
|> put_view(MyAppWeb.ChangesetView)
|> render("error.json", changeset: changeset)
end
def call(conn, {:error, something}), do: ...
But Ecto.NoResultsError that can be raised by get_page!, handled by Plug.Exception implicitly and then may be directed to action_fallback, but not in dev environment, because in dev we may want to debug those errors earlier.
-
You are right! It should be placed outside in this example, if you don’t care about binding scope; as @Sebb said he would limit the scope of
pagebinding, but in this example it does not matter. -
cms_page_path(conn, :show, page)just works because it seespagebinding, there is no inner scope betweenwith ... do, only betweenwith ... end, if I understood your question.
everywhere = 1
with only_inside_a = 2,
only_inside_b = 3 do
IO.puts(everywhere) # 1
IO.puts(only_inside_a) # 2
IO.puts(only_inside_b) # 3
end
IO.puts(everywhere) # 1
IO.puts(only_inside_a) # ERROR!
IO.puts(only_inside_b) # ERROR!






















