# Flash stopped working

**URL:** <https://www.ruby-forum.com/t/flash-stopped-working/172868>\
**Category:** Rails\
**Created:** [July 29, 2009, 6:40am UTC](https://www.ruby-forum.com/t/flash-stopped-working/172868 "2009-07-29T06:40:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [July 29, 2009, 6:40am UTC](https://www.ruby-forum.com/t/flash-stopped-working/172868/1 "2009-07-29T06:40:21Z")

</div>

I had a working 1.2 app now being updated to 2.3. I’m using a flash  
message which has worked fine. After the update to 2.3, the message no  
longer displays when it should.

In application\_controller.rb, I do a simple conditional to see if a  
session has expired (time based). If it has, I reset\_session, set a  
flash message, and redirect\_to the login page.

if — conditionals—  
reset\_session  
flash[:session\_expired] = true  
redirect\_to(:controller =\> :login, :action =\> :login)  
return false  
end

And the view uses a straightforward snippet:

\<% if flash[:session\_expired] -%\>

Your session expired. Please login to start again.

 \<% end -%\>

And using \<%= debug(flash) %\> display an empty hash.

This just seems too simple to not work, and it worked just fine with  
Rail 1.2.

Has something changed? Somethig that didn’t interfere and reset the  
flash in 1.2 that now does?

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [July 29, 2009, 2:37pm UTC](https://www.ruby-forum.com/t/flash-stopped-working/172868/2 "2009-07-29T14:37:40Z")

</div>

Make sure you have:

\<%= flash[:notice] %\>

… in your view else no flash notice will display.

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [July 29, 2009, 3:12pm UTC](https://www.ruby-forum.com/t/flash-stopped-working/172868/3 "2009-07-29T15:12:43Z")

</div>

On Jul 29, 12:40 am, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> And using \<%= debug(flash) %\> display an empty hash.
> 
> This just seems too simple to not work, and it worked just fine with  
> Rail 1.2.
> 
> Has something changed? Somethig that didn’t interfere and reset the  
> flash in 1.2 that now does?

Session handling has changed (several times) between 1.2 and 2.3. I  
think the key thing here is likely to be the fact that you’re calling  
reset session and that the flash is stored in the session. I’d check  
the cookies going back and forth between the browser and your app to  
see exactly what is going on right now (maybe something odd like the  
flash object still being in the session object that is being dumped  
rather than the new one or something like that

Fred

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [July 29, 2009, 7:08pm UTC](https://www.ruby-forum.com/t/flash-stopped-working/172868/4 "2009-07-29T19:08:06Z")

</div>

Frederick C. wrote:

> On Jul 29, 12:40ï¿½am, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > And using \<%= debug(flash) %\> display an empty hash.
> > 
> > This just seems too simple to not work, and it worked just fine with  
> > Rail 1.2.
> > 
> > Has something changed? Somethig that didn’t interfere and reset the  
> > flash in 1.2 that now does?
> 
> Session handling has changed (several times) between 1.2 and 2.3. I  
> think the key thing here is likely to be the fact that you’re calling  
> reset session and that the flash is stored in the session. I’d check  
> the cookies going back and forth between the browser and your app to  
> see exactly what is going on right now (maybe something odd like the  
> flash object still being in the session object that is being dumped  
> rather than the new one or something like that

Yeah this is real weird to me. I added log lines at various steps to see  
what was happening

if — conditionals—  
# A  
reset\_session  
# B  
flash[:session\_expired] = true  
# C  
redirect\_to(:controller =\> :login, :action =\> :login)  
# E  
return false  
end

\<% # D %\>  
\<% if flash[:session\_expired] -%\>

Your session expired....

 \<% end -%\>

#A = full session data  
#B = session is empty  
#C = session has the flash I am expecting  
#D = session is empty  
#E = session has the flash I am expecting

So, there’s some rather unintuitive order of operations going on here it  
looks like.

I guess I’ll hack it some other way.

– gw
