# Flash\[\] not shown

**URL:** <https://www.ruby-forum.com/t/flash-not-shown/94366>\
**Category:** Rails\
**Created:** [May 2, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/flash-not-shown/94366 "2006-05-02T14:36:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [May 2, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/flash-not-shown/94366/1 "2006-05-02T14:36:49Z")

</div>

I am using the following code (inspired by one of the books) to check if  
the user’s session should have timed out.

# Check to see if the user has been inactive for longer than the

# expiry period. If they have, reset the session.

def check\_timeout  
if session[:expires\_at] != nil  
@time\_left = (session[:expires\_at] - Time.now).to\_i  
unless @time\_left \> 0  
reset\_session  
# TODO - This flash is never shown, because we redirect maybe?  
flash[:error] = ‘Your session has timed out, please login to  
continue.’  
redirect\_to :controller =\> ‘security’, :action =\> ‘login’ and  
return false  
end  
end  
end

However, the flash is never shown. The view includes the correct code  
and a flash is shown if the user enters an incorrect username/password.  
At one point, the flash did work (before I changed some code) but I have  
no idea what actually broke it.

The same happens for the logout event, which simply calls reset\_session,  
sets the flash then redirects as above (in that order, so I’m not wiping  
the flash out from the session I hope).

Is there any reason that the flash wouldn’t be shown?

Cheers.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/flash-not-shown/94366/2 "2006-05-03T18:59:32Z")

</div>

I don’t know if it’s relevant or not, but when i implemented the  
‘lightning  
fast javascript auto completion’ recipe, which involved using a  
controller  
action to load a javascript file, that action ate my flash before it got  
where it was supposed to go - the next ‘real’ action.

I had to put a flash.keep statement in that action so that the contents  
would survive til the next real load.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/flash-not-shown/94366/3 "2006-05-03T18:59:34Z")

</div>

how to handle multiple flash keys (See related posts)  
posted by Scott R. on rails list

I generally like to add something like this to my application\_helper.rb:

def flash\_div \*keys  
keys.collect { |key| content\_tag(:div, flash[key],  
:class =\> “flash\_#{key}”) if  
flash[key] }.join  
end

…and then this in the section of layouts/application.rhtml:

\<%= flash\_div :warning, :notice %\>

Now, if my controller puts anything into flash[:warning] or  
flash[:notice],  
they’ll render like:

Warning here

Notice here

Handling the CSS styling

.flash\_notice {  
color: green;  
font-size: 8pt;  
}
