Flash not clearing?

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.

ok, nevermind - i RTFM:
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

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

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