The Spaghetti Refactory Established 2015

Rails' flash vs flash.now

I've seen these two things on several projects and never knew the difference. Until now!

 Boiled down to the very basics, use flash.now before a render call, and flash before a redirect_to.

  flash persists across an action, so if you use flash for a render, the flash message will show up on the rendered page AND the next page after clicking a link. Conversely, if you run flash.now on a redirect_to, you won't even see the message because the flash.now doesn't persist across requests. 

Thanks to these resources:
http://trace.adityalesmana.com/2010/10/difference-between-flash-and-flash-now-in-ruby/
http://ionrails.com/2009/09/19/flashnotice-vs-flash-nownotice/

Tags