For some very odd reasons, flash[] evaluates to nil inside a partial, but not elsewhere. This was not the case with previous rails. I have a controller called Stories, so in /layouts/stories I can access flash[], but if I render :partial => ''flash'' inside the layout, and _flash contains flash[], it would evaluate to nil and crash my app. Is there something that works differently with Rail 2.0? it was OK before the update. I can use flash[] in helpers and controllers with no problems. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Seems to work for me. On Dec 26, 2007 4:59 PM, Sharkie Landshark <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > For some very odd reasons, flash[] evaluates to nil inside a partial, > but not elsewhere. > > This was not the case with previous rails. > > I have a controller called Stories, so in /layouts/stories I can access > flash[], but if I render :partial => ''flash'' inside the layout, and > _flash contains flash[], it would evaluate to nil and crash my app. > > Is there something that works differently with Rail 2.0? it was OK > before the update. > > I can use flash[] in helpers and controllers with no problems. > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 26 Dec 2007, at 06:29, Sharkie Landshark wrote:> > For some very odd reasons, flash[] evaluates to nil inside a partial, > but not elsewhere. > > This was not the case with previous rails. > > I have a controller called Stories, so in /layouts/stories I can > access > flash[], but if I render :partial => ''flash'' inside the layout, and > _flash contains flash[], it would evaluate to nil and crash my app. > > Is there something that works differently with Rail 2.0? it was OK > before the update. >Prior to rails 2.0, @flash contained the same thing as flash (but was deprecated). When you do render :partial => ''flash'', it picks up on the @flash variable (which is still there but nil) and assigns that to flash in your partial. So you can get round this by: -renaming your partial -using flash()[:foo] instead of flash[:foo] (which will tell ruby to do the method call rather than use the local variable Fred
Frederick Cheung wrote:> On 26 Dec 2007, at 06:29, Sharkie Landshark wrote: > >> >> Is there something that works differently with Rail 2.0? it was OK >> before the update. >> > Prior to rails 2.0, @flash contained the same thing as flash (but was > deprecated). > When you do render :partial => ''flash'', it picks up on the @flash > variable (which is still there but nil) and assigns that to flash in > your partial. > So you can get round this by: > -renaming your partial > -using flash()[:foo] instead of flash[:foo] (which will tell ruby to > do the method call rather than use the local variable > > FredThank you. This had be worried that something was seriously wrong with my configuration. Is this to be changed sometime soon? In that it will not pick up @flash? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
When assigning flash, use flash[:notice] instead of @flash[:notice]. As Fred said, that was deprecated in Rails 2.0 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I just ran into this problem too. Thanks for the advice Frederick, as that was the issue. I named my partial "flash", and I forget that partials automatically get a local variable with the same name. For example, if you create a partial named "product", and then use <%= render :partial => "product", :collection => @products %> The partial will have a local variable "product" that represents the product for each one. Rails will happily override the flash hash with the partial name (and set it to nil). On Dec 26, 6:49 am, Sharkie Landshark <rails-mailing-l...@andreas- s.net> wrote:> Frederick Cheung wrote: > > On 26 Dec 2007, at 06:29, Sharkie Landshark wrote: > > >> Is there something that works differently with Rail 2.0? it was OK > >> before the update. > > > Prior to rails 2.0, @flash contained the same thing as flash (but was > > deprecated). > > When you do render :partial => ''flash'', it picks up on the @flash > > variable (which is still there but nil) and assigns that to flash in > > your partial. > > So you can get round this by: > > -renaming your partial > > -using flash()[:foo] instead of flash[:foo] (which will tell ruby to > > do the method call rather than use the local variable > > > Fred > > Thank you. This had be worried that something was seriously wrong with > my configuration. Is this to be changed sometime soon? In that it will > not pick up @flash? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---