title: Rails nil errors - any way to stop them?
body: <p>I've been learning Rails for the past 6 months.  I think it's great! </p>
  
  <p>But, 99% of errors my app gets are nil errors.  I'm either trying to display a field that is nil or a foreign key is pointing to a record that has been deleted.  </p>
  
  <p>I have this type of code in many places:</p>
  
  <pre><code>        &lt;% if location.parent != nil %&gt;
            &lt;td&gt;&lt;%= location.parent.name %&gt;&lt;/td&gt;
          &lt;% else %&gt;
            &lt;td&gt;&lt;/td&gt;
          &lt;% end %&gt;
  
        &lt;% if location.client_id != nil %&gt;
          &lt;td&gt;&lt;%= location.client.client_name %&gt;&lt;/td&gt;
        &lt;% else %&gt;
          &lt;td&gt;&lt;/td&gt;
        &lt;% end %&gt;
  </code></pre>
  
  <p>I really wish Rails would just show a blank when the field is nil!  Or, set a flash with an error and still show the page.  Instead, the page bombs.  On Heroku, you get the "Sorry, somethings wrong...."</p>
  
  <p>Is there any way to better handle blank fields? Is there a better way to code the above?  Is there some Rails setting I'm not aware of?  Is there a gem to handle these type of errors?</p>