# Flash message not clear

**URL:** <https://www.ruby-forum.com/t/flash-message-not-clear/191089>\
**Category:** Rails\
**Created:** [July 5, 2010, 6:25am UTC](https://www.ruby-forum.com/t/flash-message-not-clear/191089 "2010-07-05T06:25:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florent2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eada6e/32.png) [@Florent2](https://www.ruby-forum.com/u/Florent2)\
**Post date:** [July 5, 2010, 6:25am UTC](https://www.ruby-forum.com/t/flash-message-not-clear/191089/1 "2010-07-05T06:25:31Z")

</div>

Hello,

I have a Rails 3 beta 4 where flash messages are not cleared when they  
should be. Please note that on a freshly created Rails 3 beta 4  
application I do not face the problem. I searched for something flash  
specific in my application that could cause the problem, but I found  
nothing.

In the home page controller action I set flash.now.notice = “hello”.  
This flash message is correctly displayed on the home page.

But when I request another page, the flash message is still displayed  
although I do not set a flash message in this other page controller  
action.

In my application controller, I log the content of the  
session[‘flash’] object in a before filter and in an after filter.  
Here is what I get:

1. request on the homepage setting the flash message:

- before filter: session[‘flash’] = nil
- after filter : session[‘flash’] = {:notice=\>“hello”}

1. request on another page not setting the flash message:

- before filter: session[‘flash’] = {“notice”=\>“hello”}
- after filter : session[‘flash’] = {“notice”=\>“hello”}

I don’t understand why the session[‘flash’] contains {“notice” =\>  
“hello”} at the beginning of the request of the second page.  
The :notice key has correctly disappeared but a new key “notice” has  
appeared. That’s what provokes the unwanted display of the flash  
message on the second request.

I’ve looked into the ActionDispatch::Flash class and tried to log what  
happened in the sweep function  
[http://github.com/rails/rails/blob/master/actionpack/lib/action\_dispatch/middleware/flash.rb#L120](http://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/flash.rb#L120)  
The problem is that the key “notice” is not deleted as @used set  
contains :notice where the flash keys contains “notice”.

I could not figure out how and where in the code the flash object is  
reconstructed from the cookie session. Also, is it possible from the  
browser to read the content of the Rails cookie session to directly  
see how is the flash stored in the cookie?

Any help or indication to further dig in my problem would be greatly  
appreciated 🙂

Florent

---

<div class="post-metadata">

**Author:** ![Florent2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eada6e/32.png) [@Florent2](https://www.ruby-forum.com/u/Florent2)\
**Post date:** [July 6, 2010, 5:17pm UTC](https://www.ruby-forum.com/t/flash-message-not-clear/191089/2 "2010-07-06T17:17:51Z")

</div>

Finally I could reproduce the bug in a freshly created Rails 3  
application, requiring one by one the gems I used in my first  
application. The bug occurs when both twitter and sg-ruby gems are  
required from Gemfile. If only one of both is required, the bug  
disappears. Reading through the code of both gems, I could not figure  
out how the bug appears. So to avoid the bug I just switched from the  
twitter gem to the grackle gem.

Florent
