Colin Steele
2005-Nov-08 16:18 UTC
unexpected interaction between flash and render_component(_as_string)
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
Scott Barron
2005-Nov-08 17:14 UTC
Re: unexpected interaction between flash and render_component(_as_string)
Rails version (please always include this when reporting problems)? On Nov 8, 2005, at 11:18 AM, Colin Steele wrote:> 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 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com http://rubyi.st
Colin Steele
2005-Nov-08 18:31 UTC
Re: unexpected interaction between flash and render_component(_as_string)
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.
On Tue, 2005-11-08 at 12:14 -0500, Scott Barron wrote:> Rails version (please always include this when reporting problems)?
>
> On Nov 8, 2005, at 11:18 AM, Colin Steele wrote:
>
> > 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
> >
> >
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> >
Oyku Gencay
2005-Nov-08 18:50 UTC
Re: unexpected interaction between flash and render_component(_as_string)
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. On 08.Kas.2005, at 20:31, Colin Steele wrote:> 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. > > > > On Tue, 2005-11-08 at 12:14 -0500, Scott Barron wrote: > >> Rails version (please always include this when reporting problems)? >> >> On Nov 8, 2005, at 11:18 AM, Colin Steele wrote: >> >> >>> 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 >>> >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >