# Flash not clearing?

**URL:** <https://www.ruby-forum.com/t/flash-not-clearing/103078>\
**Category:** Rails\
**Created:** [May 1, 2007, 3:53pm UTC](https://www.ruby-forum.com/t/flash-not-clearing/103078 "2007-05-01T15:53:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jemminger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@jemminger](https://www.ruby-forum.com/u/jemminger)\
**Post date:** [May 1, 2007, 3:53pm UTC](https://www.ruby-forum.com/t/flash-not-clearing/103078/1 "2007-05-01T15:53:07Z")

</div>

hi all,

using rails 1.2.3 on windows xp

i have a controller method like so:

def index  
…do stuff…  
if some\_error  
flash[:notice] = “error!”  
end  
end

and the layout has:  
\<% if flash[:notice] -%\>

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

the form for index submits via GET method. if i cause the some\_error  
condition through the form, i get the flash message as expected.  
however, if i immediately submit again with conditions that do not  
cause some\_error, i still get the flash message again. it takes until  
submitting a third time for the flash message to clear. isn’t it  
supposed to clear itself after it renders the first time in the  
layout? i know i’m not setting it again because i have a debug  
statement when it gets set in the controller.

---

<div class="post-metadata">

**Author:** ![jemminger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@jemminger](https://www.ruby-forum.com/u/jemminger)\
**Post date:** [May 1, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/flash-not-clearing/103078/2 "2007-05-01T15:58:08Z")

</div>

ok, nevermind - i RTFM:  
[http://api.rubyonrails.org/classes/ActionController/Flash/FlashHash.html](http://api.rubyonrails.org/classes/ActionController/Flash/FlashHash.html)

the method  
flash.now[:message] = “Hello current action”

is supposed to be used when rendering the current action;  
flash[:notice] = ‘some message’ is to be used when using redirect\_to

---

<div class="post-metadata">

**Author:** ![jemminger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@jemminger](https://www.ruby-forum.com/u/jemminger)\
**Post date:** [May 1, 2007, 3:59pm UTC](https://www.ruby-forum.com/t/flash-not-clearing/103078/3 "2007-05-01T15:59:08Z")

</div>

What you describes maps with my understanding of flash. From  
ActiveController:Flash: “Anything you place in the flash will be  
exposed to the very next action and then cleared out.”

I think what you want is flash.now:  
flash.now[:notice] = “error!”

- Hal

---

<div class="post-metadata">

**Author:** ![jemminger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@jemminger](https://www.ruby-forum.com/u/jemminger)\
**Post date:** [May 1, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/flash-not-clearing/103078/4 "2007-05-01T16:27:13Z")

</div>

yep - just saw that in the docs too. thanks for the reply!
