Hi all, I have a template that is sometimes given a local like so: render :partial => ''shared/new_addresses'', :locals => {:addresses => addresses} In the partial I do this to make sure everything is cool: if defined? addresses && !addresses.nil? && addresses[:z_address] @address = addresses[:z_address] end Now, here''s where things get weird. After the app has been running a while in production I start getting exceptions being thrown due to addresses being nil on the assignment line above. Even though I make sure it isn''t in the if statement! If I do this: if defined? addresses && !addresses.nil? && addresses[:z_address] if !addresses.nil? @address = addresses[:z_address] end end I don''t get the errors. Any one have a clue as to what is happening here? Cheers, --Ed --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> render :partial => ''shared/new_addresses'', :locals => {:addresses => > addresses} > > In the partial I do this to make sure everything is cool: > > if defined? addresses && !addresses.nil? && addresses[:z_address] > @address = addresses[:z_address] > end > >defined? will not work as expected with variables passed as locals to a partial. You should use instead local_assigns.has_key? addresses You could also work aroud that by doing addresses ||= nil That way if it was undefined initially, it will be nil after that, so you can check it with addresses.nil? directly regards, javier ramirez -- -------- Estamos de estreno... si necesitas llevar el control de tus gastos visita http://www.gastosgem.com !!Es gratis!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Javier! Using local_assigns.has_key? does the trick. Cheers, --Ed On Mar 8, 6:06 pm, javier ramirez <jrami...-7iWCczGtl7hBDgjK7y7TUQ@public.gmane.org> wrote:> > render :partial => ''shared/new_addresses'', :locals => {:addresses => > > addresses} > > > In the partial I do this to make sure everything is cool: > > > if defined? addresses && !addresses.nil? && addresses[:z_address] > > @address = addresses[:z_address] > > end > > defined? will not work as expected with variables passed as locals to a > partial. You should use instead > local_assigns.has_key? addresses > > You could also work aroud that by doing > addresses ||= nil > > That way if it was undefined initially, it will be nil after that, so > you can check it with addresses.nil? directly > > regards, > > javier ramirez > > -- > -------- > Estamos de estreno... si necesitas llevar el control de tus gastos visitahttp://www.gastosgem.com!!Es gratis!!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---