class

Session::Flash

Inherits JSON::Serializable < Reference < Object

Flash provides temporary message storage that persists for exactly one request. Messages added to next are available in now on the next request, then cleared.

Example usage:

In controller action (e.g., after login)

flash.next["notice"] = "Welcome back!"

In next request (e.g., dashboard view)

flash.now["notice"] # => "Welcome back!"

For same-request messages (e.g., validation errors)

flash.now["error"] = "Invalid input"

Constructors

new(pull : JSON::PullParser)
Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Instance methods

[](key : String) : String | Nil

Convenience method to get a flash message (checks now first)

Source
[]=(key : String, value : String) : String

Convenience method to set a flash message for next request

Source
[]?(key : String) : String | Nil

Alias for [] that explicitly returns nil when not found

Source
alert
Source
alert=(message : String) : String
Source
clear_now

Clear current request messages

Source
discard(key : String) : Nil

Discard a flash message (won't appear in next request)

Source
discard_all

Discard all flash messages

Source
empty?

Check if there are any flash messages

Source
error
Source
error=(message : String) : String
Source
has_key?(key : String) : Bool

Check if a flash message exists

Source
info
Source
info=(message : String) : String
Source
keep(key : String) : Nil

Keep a flash message for another request

Source
keep_all

Keep all flash messages for another request

Source
keys

Get all message keys

Source
next

Messages to be available in next request

Source
notice

Common flash message helpers

Source
notice=(message : String) : String
Source
now

Messages available in current request (read-only from perspective of previous request)

Source
rotate!

Rotate flash messages: move next -> now, clear next Called automatically at start of each request

Source
success
Source
success=(message : String) : String
Source
to_h

The messages a view shows: this request's, and those set during it.

Source
warning
Source
warning=(message : String) : String
Source