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

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...