title: How to check if an object is nil in a view in Ruby?
body: <p>I would like to display a line of text only if an object called @foo is set.
  In my view, I'm trying something like this:</p>
  
  <pre><code>&lt;% if !@foo.new_record? || !@foo.nil? %&gt;
      Foo is not a new record or nil
  &lt;% end %&gt;
  </code></pre>
  
  <p>But this fails, returning <code>You have a nil object when you didn't expect it!</code>
  I'm pretty sure this happens because of the <code>new_record?</code> method.
  How do I check if something is not a new record or nil without causing an error?
  In PHP, it would be achieved by asking <code>if(!empty($foo))</code> but even the <code>empty?</code> method in rails causes the same error to be returned.</p>
  
  <p>Any ideas?</p>