There’s a subtle difference between flash
and flash.now
. The flash
variable is designed to be used before a redirect, and it persists on the resulting page for one request—that is, it appears once, and disappears when you click on another link. Unfortunately, this means that if we don’t redirect, and instead simply render a page (as in Listing 9.8), the flash message persists for two requests: it appears on the rendered page but is still waiting for a “redirect” (i.e., a second request), and thus appears again if you click a link.
To avoid this weird behavior, when render
ing rather than redirect
ing we use flash.now
instead of flash
. The flash.now
object is specifically designed for displaying flash messages on rendered pages. If you ever find yourself wondering why a flash message is showing up where you don’t expect it, chances are good that you need to replace flash
withflash.now
.