views:

168

answers:

1

My basic use case is do some processing, set flash[:notice], and then redirect to a new page. From what I can tell, redirects reset the flash tag (please correct me if I'm wrong). Is there a way to gain persistence? Using sessions isn't an option, and I have hacked around the problem using cookies, but I think there's got to be a better way.

+2  A: 

The flash hash persists for exactly one redirect or render. So you should be fine with the default settings.

If you need to keep the flash hash for another request/redirect, you can call flash.keep.

flash.keep # keep the entire flash hash around for an extra request.
flash.keep(:notice) # keep just flash[:notice] for an extra request.
EmFi
Is there any possible reason that this might not always be true (such as sessions being disabled)? It is certainly not the case in my uses (flash[:notice] should be displayed as part of the standard layout, but it isn't visible unless it is set before a render as opposed to a redirect).
Tom Bennett
What happens when you explicitly reference flash[:notice] in a view?
EmFi
After a redirect? Nothing. If there is no redirect involved, I can see the same string assigned.
Tom Bennett
Any chance you're calling flash.discard anywhere? That would result a flash hash not surviving a redirect.
EmFi
nope, that's not being called
Tom Bennett
The only other thing I could think of is that you're redirecting multiple times. Keep only makes the flash persist for one extra redirect when it's called.
EmFi