I’m using rails 2.2.2 in a particular app, and upgrading isn’t an option
right now (in case this is a version-specific problem).
When you do flash[:notice] = “blah”, that message persists over the next
redirect, ie into the next action. When you do flash.now[:notice] =
“blah”, it doesn’t persist into the next action.
However, sometimes in the code you might not exactly know what you want
to do at the end of the action, ie sometimes you might redirect and
sometimes you might re-render a template. If you do flash[:notice] =
“blah” and then do a render, then click from that page to somewhere
else completely, the flash message is still hanging around, completely
out of context.
it’s possible to deal with this by making sure that it’s always a
flash.now when you’re going to render, and always a straight flash when
you’re going to redirect. But this seems clumsy and error prone, and
leads to messier controller code.
What would seem like an ideal solution to me is to look up the hooks
that action loading has into the FlashHash, and whatever it does, make
the render action do that as well. So, the flash gets displayed once,
then wiped, whether you render or redirect.
Before i go off on a quest to do this, does anyone have any sage advice?
Is this plan doomed to failure?