I am having a problem with the Flash that seems a bit odd. I am using the Flash to pass an object between actions. I have this code: if @new_issue.save flash[:new_issue] = @new_issue redirect_to :action => ''features_departments'' else render :action => ''index'' end If I log out the contents of flash[:new_issue] right before I redirect, it contains the object I expect. The problem is that if I attempt to do something like: <%= @flash[:new_issue].title %> In the features_departments.rhtml file, I get this: undefined method `title'' for nil:NilClass If I log out the contents of the Flash at that point, it is nil. What am I doing wrong? Looking at the Agile book, it seems like I am using the Flash as intended. Any tips appreciated.
Hunter Hillegas wrote:> I am having a problem with the Flash that seems a bit odd. > > I am using the Flash to pass an object between actions. > > I have this code: > > if @new_issue.save > flash[:new_issue] = @new_issue > redirect_to :action => ''features_departments'' > else > render :action => ''index'' > end > > If I log out the contents of flash[:new_issue] right before I redirect, it > contains the object I expect. > > The problem is that if I attempt to do something like: > > <%= @flash[:new_issue].title %> > > In the features_departments.rhtml file, I get this: > > undefined method `title'' for nil:NilClass > > If I log out the contents of the Flash at that point, it is nil. > > What am I doing wrong? Looking at the Agile book, it seems like I am using > the Flash as intended. > > Any tips appreciated. >I''m pretty certain that the contents of @flash are stored using sessions. Maybe you have something simple like cookies disabled or something else that is stopping sessions from working correctly. Maybe you could try storing something in a session between two page calls and see if that is also reset, therefore indicating a session problem of one form or another. Chris
Chris, Thanks for responding. I am able to use the session for other items - I store information regarding the logged in user there without any trouble. That should indicate the session is working, yes? What else could be going wrong? Thanks, Hunter> From: Chris Roos <chris-zoUjy1rb4AnQXOPxS62xeg@public.gmane.org> > Reply-To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > Date: Sun, 24 Jul 2005 11:20:49 +0100 > To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > Subject: Re: [Rails] Flash Contents nil on Redirect > > Hunter Hillegas wrote: >> I am having a problem with the Flash that seems a bit odd. >> >> I am using the Flash to pass an object between actions. >> >> I have this code: >> >> if @new_issue.save >> flash[:new_issue] = @new_issue >> redirect_to :action => ''features_departments'' >> else >> render :action => ''index'' >> end >> >> If I log out the contents of flash[:new_issue] right before I redirect, it >> contains the object I expect. >> >> The problem is that if I attempt to do something like: >> >> <%= @flash[:new_issue].title %> >> >> In the features_departments.rhtml file, I get this: >> >> undefined method `title'' for nil:NilClass >> >> If I log out the contents of the Flash at that point, it is nil. >> >> What am I doing wrong? Looking at the Agile book, it seems like I am using >> the Flash as intended. >> >> Any tips appreciated. >> > I''m pretty certain that the contents of @flash are stored using > sessions. Maybe you have something simple like cookies disabled or > something else that is stopping sessions from working correctly. Maybe > you could try storing something in a session between two page calls and > see if that is also reset, therefore indicating a session problem of one > form or another. > > Chris > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On 24 Jul 2005, at 22:58, Hunter Hillegas wrote:> Chris, > > Thanks for responding. > > I am able to use the session for other items - I store information > regarding > the logged in user there without any trouble. > > That should indicate the session is working, yes? > > What else could be going wrong?Anything you store in flash only survives until the next request. And in your case, the next request is a redirect - this is what''s eating the flash message. You need to put a: flash.keep Before the redirect if you want flash to survive the redirect. ...j