skip to content

Flash Messages & Session Stores

Rails keeps per-user state in session[], by default an encrypted cookie capped near 4 KB, and passes one-request messages through flash. Interviewers ask which store to pick and when to use flash.now.

part ofRuby on Railsread it →
on this pageshow

explore

questions

4

In a Rails controller, when do you use flash.now instead of flash, and what do flash.keep and add_flash_types add?

level: middleimportance: must knowfreq 65%

basics

~20 s

flash[:notice] is shown on the next request, so it pairs with redirect_to; flash.now[:alert] is shown only in the current request, so it pairs with render. flash.keep carries entries through one more request, and add_flash_types adds keys usable like notice: and alert:.

open as a page