I''m deploying and running into problems that I didn''t have in the development environment... In development, I have a section of code that says something like: <% for charity in @charities %> <%= blah blah blah %> <% end %> and it works fine... when I go to deployment, it throws an error saying it doesn''t recognize this class variable (because there weren''t any charities entered in the db). When I put an ''if'' statement in front of the ''for'' loop, it works: <% if @charities %> <% for charity in @charities %> <%= blah blah blah %> <% end %> I kinda have 2 questions: 1. Why does not having the ''if'' statement work in development, but not in production? 2. Is there a cleaner way to write this code? Thanks a HEAP :) -- 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 -~----------~----~----~----~------~----~------~--~---
Zack Chandler
2007-Mar-28 15:05 UTC
Re: Is there a better way to do this? - newbie question
Dustin, You are probably not initializing @charities in the controller if there are none. I guess you could do this (see below) although I would probably just check your controller code and always init @charities... <% for charity in (@charities || []) %> <%= blah blah blah %> <% end %> -- Zack Chandler http://depixelate.com On 3/28/07, Dustin Anderson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''m deploying and running into problems that I didn''t have in the > development environment... > > In development, I have a section of code that says something like: > > <% for charity in @charities %> > <%= blah blah blah %> > <% end %> > > and it works fine... > > when I go to deployment, it throws an error saying it doesn''t recognize > this class variable (because there weren''t any charities entered in the > db). > > When I put an ''if'' statement in front of the ''for'' loop, it works: > > <% if @charities %> > <% for charity in @charities %> > <%= blah blah blah %> > <% end %> > > I kinda have 2 questions: > 1. Why does not having the ''if'' statement work in development, but > not in production? > 2. Is there a cleaner way to write this code? > > Thanks a HEAP :) > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Mar-28 15:17 UTC
Re: Is there a better way to do this? - newbie question
> I''m deploying and running into problems that I didn''t have in the > development environment... > > In development, I have a section of code that says something like: > > <% for charity in @charities %> > <%= blah blah blah %> > <% end %> > > and it works fine... > > when I go to deployment, it throws an error saying it doesn''t recognize > this class variable (because there weren''t any charities entered in the > db). > > When I put an ''if'' statement in front of the ''for'' loop, it works: > > <% if @charities %> > <% for charity in @charities %> > <%= blah blah blah %> > <% end %> > > I kinda have 2 questions: > 1. Why does not having the ''if'' statement work in development, but > not in production?It works in production because you said there are rows in the production database that get populated into @charities. So @charities contains something.> 2. Is there a cleaner way to write this code?How are you populating @charities? Even in development with no records @charities should get set to [] in which case that for loop should work... -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dustin Anderson
2007-Mar-28 17:06 UTC
Re: Is there a better way to do this? - newbie question
Philip Hallstrom wrote:>> > How are you populating @charities? Even in development with no records > @charities should get set to [] in which case that for loop should > work... > > -philipThanks gang - I''m running edge rails and screwed that up... we didn''t have the vendor/rails directory deploying - so I think it was running on an older version of rails that wasn''t as "smart"... -- 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 -~----------~----~----~----~------~----~------~--~---