# Unexpected interaction between flash and render\_component(\_a

**URL:** <https://www.ruby-forum.com/t/unexpected-interaction-between-flash-and-render-component-a/47527>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/unexpected-interaction-between-flash-and-render-component-a/47527 "2005-11-12T12:49:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![colin\_steele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@colin\_steele](https://www.ruby-forum.com/u/colin_steele)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/unexpected-interaction-between-flash-and-render-component-a/47527/1 "2005-11-12T12:49:19Z")

</div>

Hi, folks. I am experiencing cognitive dissonance about an unexpected  
(and to me, non-intuitive) interaction between flash and  
render\_component\_as\_string.

It seems that if a controller action calls render\_component\_as\_string,  
sets some flash data, and does a redir, the flash data is lost. It  
works as you’d expect if render\_component is not called. To illustrate:

class TestController \< ApplicationController

def unexpected  
render\_component\_as\_string(:controller=\>‘test’,  
:action=\>‘other’)  
flash[:notice] = ‘Attention please.’  
redirect\_to :action =\> ‘show’  
end

def expected  
flash[:notice] = ‘Attention please.’  
redirect\_to :action =\> ‘show’  
end

def show  
render\_text(flash.inspect)  
end

def other  
render\_text(‘yep’)  
end

end

When I hit test/unexpected, I get back an empty hash. Where’d my flash  
data go? Why does render\_component\_as\_string seem to make it disappear?

–Colin

---

<div class="post-metadata">

**Author:** ![colin\_steele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@colin\_steele](https://www.ruby-forum.com/u/colin_steele)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/unexpected-interaction-between-flash-and-render-component-a/47527/2 "2005-11-12T12:49:20Z")

</div>

Rails version (please always include this when reporting problems)?

---

<div class="post-metadata">

**Author:** ![colin\_steele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@colin\_steele](https://www.ruby-forum.com/u/colin_steele)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/unexpected-interaction-between-flash-and-render-component-a/47527/3 "2005-11-12T12:49:20Z")

</div>

The lastest:

colin@ubuntu:~/projects/selene/trunk$ gem list rails

\*\*\* LOCAL GEMS \*\*\*

rails (0.14.3, 0.14.2)  
Web-application framework with template engine, control-flow layer,  
and ORM.

---

<div class="post-metadata">

**Author:** ![colin\_steele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@colin\_steele](https://www.ruby-forum.com/u/colin_steele)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/unexpected-interaction-between-flash-and-render-component-a/47527/4 "2005-11-12T12:49:20Z")

</div>

This also happened to me. Check the rails bugtrack and you’ll find a  
patch for it. Unless patched, during the rendering, flash is  
consumed. I was a bit disappointed when I first found this out but  
after patching, it was gone.
