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.
views:
168answers:
1
+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
2009-10-16 19:19:22
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
2009-10-16 20:14:42
What happens when you explicitly reference flash[:notice] in a view?
EmFi
2009-10-16 20:50:10
After a redirect? Nothing. If there is no redirect involved, I can see the same string assigned.
Tom Bennett
2009-10-19 23:04:35
Any chance you're calling flash.discard anywhere? That would result a flash hash not surviving a redirect.
EmFi
2009-10-19 23:28:01
nope, that's not being called
Tom Bennett
2009-10-20 23:23:09
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
2009-10-21 04:55:49