Re: flash message not shown after redirect_to


I think I know what’s going on here.

Think of redirect_to like a render() call that just sends a response
causes the browser to request the page you passed to redirect_to.

There are 3 request/response cycles involved here. You are putting
in the flash in one action which then renders a page (cycle 1), then the
user clicks a link on that page to an action which redirects (cycle 2).
causes the browser to request, and the server to deliver, another page
(cycle 3). The values you put in the flash during cycle 1 will be intact
during cycle 2 but they’re gone in cycle 3.

Is this what’s goin’ down?

Solution: flash.keep()
In cycle 2, before calling redirect_to, call flash.keep . . you can pass
a key from the hash if you only want to preserve part of the flash hash.


Cool. I hadn’t come across flash.keep. Thanks, Blake.

Best regards,