Unexpected interaction between flash and render_component(_a


#1

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


#2

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


#3

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.


#4

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.