Phoenix.Controller.Flash
Handles One-time messages, often referred to as “Flash” messages. Messages can be stored in the session and persisted across redirects for notices and alerts about request state.
Examples
def index(conn, _) do
render conn, "index", notice: Flash.get(conn, :notice)
end
def create(conn, _) do
conn
|> Flash.put(:notice, "Created successfully")
|> redirect("/")
end
Summary
call(conn, ) | Clears the Message dict on new requests |
clear(conn) | Clears all flash messages |
get(conn) | Returns a message from the |
get(conn, key) | Returns a message from the |
get_all(conn, key) | Returns a list of messages by key from the |
init(opts) | |
pop_all(conn, key) | Removes all messages from the for given key, returning a |
put(conn, key, message) | Persists a message in the |
Functions
Returns a message from the Phoenix.Flash
Examples
iex> Flash.put(conn, :notice, "Hi!") |> Flash.get
%{notice: "Hi!"}
Returns a message from the Phoenix.Flash
by key
Examples
iex> Flash.put(conn, :notice, "Hello!") |> Flash.get(:notice)
"Hello!"
Returns a list of messages by key from the Phoenix.Flash
Examples
iex> conn
|> Flash.put(:notice, "hello")
|> Flash.put(:notice, "world")
|> Flash.get_all(:notice)
["hello", "world"]
Removes all messages from the for given key, returning a {msgs, conn}
pair
Examples
iex> %Conn{}
|> Flash.put(:notice, "oh noes!")
|> Flash.put(:notice, "false alarm!")
|> Flash.pop_all(:notice)
{["oh noes!", "false alarm!"], %Conn{}}