Skip to content

Add flash functionality to session#112

Merged
sdogruyol merged 1 commit intomasterfrom
flash
Feb 2, 2026
Merged

Add flash functionality to session#112
sdogruyol merged 1 commit intomasterfrom
flash

Conversation

@sdogruyol
Copy link
Copy Markdown
Member

Summary

Adds flash message support to kemal-session, enabling temporary messages that persist only until they are read (typically used for displaying notices after redirects).

Features

  • env.flash["key"] = "value" - Set a flash value
  • env.flash["key"]? - Read and automatically delete (returns nil if not found)
  • env.flash["key"] - Read and delete (raises KeyError if not found)

Flash messages are stored in the session with a _flash_ prefix and are automatically deleted after being read, making them ideal for one-time notifications.

Usage

Set a flash message

get "/" do |env|
  env.flash["notice"] = "Welcome!"
  env.redirect "/dashboard"
end

Read and consume the flash message

get "/dashboard" do |env|
  if notice = env.flash["notice"]?
    "<div class='alert'>#{notice}</div>"
  else
    "Dashboard"
  end
end

@sdogruyol
Copy link
Copy Markdown
Member Author

//cc @mamantoha

@mamantoha
Copy link
Copy Markdown
Contributor

mamantoha commented Feb 2, 2026

Hi @sdogruyol . Does this duplicate the functionality of https://github.com/crystal-garage/kemal-flash?

I will check later.

@sdogruyol
Copy link
Copy Markdown
Member Author

@mamantoha pretty much the same API with a simpler implementation that only supports String values

Copy link
Copy Markdown
Contributor

@mamantoha mamantoha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sdogruyol sdogruyol merged commit 05aa55a into master Feb 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants