# Flash notices are not accessible on next request

**URL:** <https://www.ruby-forum.com/t/flash-notices-are-not-accessible-on-next-request/166818>\
**Category:** Rails\
**Created:** [April 29, 2009, 9:29pm UTC](https://www.ruby-forum.com/t/flash-notices-are-not-accessible-on-next-request/166818 "2009-04-29T21:29:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 29, 2009, 9:29pm UTC](https://www.ruby-forum.com/t/flash-notices-are-not-accessible-on-next-request/166818/1 "2009-04-29T21:29:14Z")

</div>

For some reason, which I cannot detect, no flash notices that I set  
prior to redirects are available after the redirect.

This standard “forgot password” action as an example:

def forgot  
if request.post?  
user = User.find\_by\_email(params[:user][:email])  
if user  
user.create\_reset\_code  
flash[:notice] = “A reset email was sent to #{user.email}”  
redirect\_back\_or\_default(’/’)  
else  
flash[:notice] = “The email #{params[:user][:email]} does not  
exist in system”  
redirect\_to forgot\_path  
end  
end  
end

If I enter a bad email address, the forgot action/view should redisplay  
with the flash message. Up until a little while ago, it did. Something  
changed, but I am not sure what it is. Flash messages that are set  
before renders do display (my layouts contain the display of the flash  
message, so are available on most every page).

Using the debugger, I have verified that just after the flash[:notice]  
statement, the flash hash is set correctly. But when processing returns  
to the forgot method after the redirect, the flash hash is empty. So it  
seems that the message is not making to the session, or is not being  
restored from the session.

Sessions are working properly otherwise.

Any thoughts would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 30, 2009, 12:41am UTC](https://www.ruby-forum.com/t/flash-notices-are-not-accessible-on-next-request/166818/2 "2009-04-30T00:41:05Z")

</div>

Tom H. wrote:

> Any thoughts would be greatly appreciated.

Ok, total beginner here. As far as I know, the flash is only available  
to the next request after the current request, and then it’s  
automatically deleted. So if your flash is empty, there must have been  
two requests since you set the flash. A redirect causes the browser to  
issue a new request. Is there a second redirect in your code somewhere?

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 30, 2009, 2:52am UTC](https://www.ruby-forum.com/t/flash-notices-are-not-accessible-on-next-request/166818/3 "2009-04-30T02:52:44Z")

</div>

7stud – wrote:

> Is there a second redirect in your code somewhere?

That is a good thought. I was thinking along the same lines, so checked  
the console after issuing a request that should end with a displayed  
flash message and saw that there was only a single redirect. I also  
tried adding “keep” to the flash set statement, but alas, no message  
appeared.

I am really stumped on this one.

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 8, 2009, 1:41pm UTC](https://www.ruby-forum.com/t/flash-notices-are-not-accessible-on-next-request/166818/4 "2009-05-08T13:41:02Z")

</div>

Tom H. wrote:

> 7stud – wrote:
> 
> > Is there a second redirect in your code somewhere?
> 
> That is a good thought. I was thinking along the same lines, so checked  
> the console after issuing a request that should end with a displayed  
> flash message and saw that there was only a single redirect. I also  
> tried adding “keep” to the flash set statement, but alas, no message  
> appeared.
> 
> I am really stumped on this one.

I had the same issue - it was because of the render\_component plugin.  
Take that out and everything worked properly.

However this might be something worth looking at too:  
[https://rails.lighthouseapp.com/projects/8994/tickets/2200-session-support-broken](https://rails.lighthouseapp.com/projects/8994/tickets/2200-session-support-broken)

Ta  
Luke

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 12, 2009, 3:58am UTC](https://www.ruby-forum.com/t/flash-notices-are-not-accessible-on-next-request/166818/5 "2009-05-12T03:58:37Z")

</div>

Luke P. wrote:

> I had the same issue - it was because of the render\_component plugin.  
> Take that out and everything worked properly.
> 
> However this might be something worth looking at too:  
> [#2200 reset\_session broken - Ruby on Rails - rails](https://rails.lighthouseapp.com/projects/8994/tickets/2200-session-support-broken)

Luke - Thanks for responding. I use embedded Active Scaffolds, so need  
to have render component installed. I commented out a line that called  
flash.sweep:

```
 def assign_shortcuts_with_render_component(request, response)
    assign_shortcuts_without_render_component(request, response)
    flash(:refresh)
    #flash.sweep if @_session && !component_request?
  end

```

which seems to make things work without breaking others, but I can’t be  
too sure. I sent a message to the author of render\_component and have  
not heard whether this is a bad thing to do.

Tom

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [May 12, 2009, 10:28am UTC](https://www.ruby-forum.com/t/flash-notices-are-not-accessible-on-next-request/166818/6 "2009-05-12T10:28:53Z")

</div>

Tom H. wrote:

> Luke - Thanks for responding. I use embedded Active Scaffolds, so need  
> to have render component installed. I commented out a line that called  
> flash.sweep:

Thanks very much for this Tom. We’re using ActiveScaffold too so this  
is really useful; let us know if you get a reply about it.

Cheers  
Luke
