class
Session::Flash
- Session::Flash
- Reference
- Object
Overview
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"
Included Modules
- JSON::Serializable
Defined in:
flash.crConstructors
Instance Method Summary
-
#[](key : String) : String | Nil
Convenience method to get a flash message (checks now first)
-
#[]=(key : String, value : String) : String
Convenience method to set a flash message for next request
-
#[]?(key : String) : String | Nil
Alias for [] that explicitly returns nil when not found
- #alert : String | Nil
- #alert=(message : String) : String
-
#clear_now : Nil
Clear current request messages
-
#discard(key : String) : Nil
Discard a flash message (won't appear in next request)
-
#discard_all : Nil
Discard all flash messages
-
#empty? : Bool
Check if there are any flash messages
- #error : String | Nil
- #error=(message : String) : String
-
#has_key?(key : String) : Bool
Check if a flash message exists
- #info : String | Nil
- #info=(message : String) : String
-
#keep(key : String) : Nil
Keep a flash message for another request
-
#keep_all : Nil
Keep all flash messages for another request
-
#keys : Array(String)
Get all message keys
-
#next : Hash(String, String)
Messages to be available in next request
-
#notice : String | Nil
Common flash message helpers
- #notice=(message : String) : String
-
#now : Hash(String, String)
Messages available in current request (read-only from perspective of previous request)
-
#rotate! : Nil
Rotate flash messages: move next -> now, clear next Called automatically at start of each request
- #success : String | Nil
- #success=(message : String) : String
-
#to_h : Hash(String, String)
The messages a view shows: this request's, and those set during it.
- #warning : String | Nil
- #warning=(message : String) : String
Constructor Detail
Instance Method Detail
Convenience method to set a flash message for next request
Messages available in current request (read-only from perspective of previous request)
Rotate flash messages: move next -> now, clear next Called automatically at start of each request
The messages a view shows: this request's, and those set during it.