Forum: Ruby on Rails Re: flash message not shown after redirect_to

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
6165aecb1a97c3ee6df433e38b49ca37?d=identicon&s=25 Blake Miller (Guest)
on 2007-04-04 23:24
(Received via mailing list)

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.

2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2007-04-05 01:16
(Received via mailing list)
Cool.  I hadn't come across flash.keep. Thanks, Blake.

Best regards,
This topic is locked and can not be replied to.