You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Set |`env.flash["key"] = "value"`| Stores the message for the next request |
216
+
| Read (optional) |`env.flash["key"]?`| Returns the value and removes it; returns `nil` if key is missing |
217
+
| Read (required) |`env.flash["key"]`| Returns the value and removes it; raises `KeyError` if key is missing |
218
+
219
+
Use `env.flash["key"]?` when the key might not be set (e.g. optional notices). Use `env.flash["key"]` when you expect the key to exist; it will raise if the message was already consumed or never set.
220
+
221
+
### Example: Form with Success/Error
222
+
223
+
```crystal
224
+
post "/contact" do |env|
225
+
if send_email(env.params.body)
226
+
env.flash["notice"] = "Message sent successfully."
227
+
else
228
+
env.flash["error"] = "Failed to send message."
229
+
end
230
+
env.redirect "/contact"
231
+
end
232
+
233
+
get "/contact" do |env|
234
+
notice = env.flash["notice"]?
235
+
error = env.flash["error"]?
236
+
# Render form and show notice/error above it
237
+
end
238
+
```
239
+
178
240
## 📊 Supported Data Types
179
241
180
242
Kemal Session supports all common Crystal types with intuitive method names:
0 commit comments