Apologies for a longer post, but on page 109, we have a discussion that tells us that we preferred to store any messages to be displayed to the user into session as a flash hash. The book says:
bq. The flash data is stored in the session in order to make it available between requests.
But then I am not sure when the flash data is cleared.
For example: /store/add_to_cart/non-existent-id -> StoreController.add_to_cart -> sends a redirect to /store/index with flash[:notice] set to “Invalid Product”. Thus, when browser now sends a request to /store/index, since the store layout is modified to look into flash[:notice] first, when the response is sent back, it contains the flash data and store’s index page.
But, when the same browser just sends a request to /store/index, the flash data does not reappear (which is what we want). But who clears the flash data set in the session and when? Since session data is available across requests, unless it’s cleared it should be available to other requests as well (or so I think).