Phoenix Flash Message: Difference between revisions
From ElixirBlocks
No edit summary |
No edit summary |
||
| Line 17: | Line 17: | ||
The flash component itself needs to be in the view | The flash component itself needs to be in the view. For a new instance it defaults to being in the the layout via app_web/layouts/app.html.heex and its accessible to all controllers. | ||
<source> | <source> | ||
<.flash_group flash={@flash} /> | <.flash_group flash={@flash} /> | ||
</source> | </source> | ||
Latest revision as of 09:12, 27 December 2024
In Phoenix the flash message is invoked from the controller.
def create(conn, %{"doink" => doink_params}) do
case Doinks.create_doink(doink_params) do
{:ok, doink} ->
conn
|> put_flash(:info, "Doink created successfully.")
|> redirect(to: ~p"/doinks/#{doink}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :new, changeset: changeset)
end
end
The flash component itself needs to be in the view. For a new instance it defaults to being in the the layout via app_web/layouts/app.html.heex and its accessible to all controllers.
<.flash_group flash={@flash} />