title: if/else in erb executing code it should not
body: <p><strong>Thanks</strong> to everyone for providing me with information! There were some very quick responses. My solution was to use a clearer test in the if. Grammar for the win!</p>
  
  <p>"You have a nil object when you didn't expect it! The error occurred while evaluating nil.name"</p>
  
  <p>This error points to the line below with "file.name".</p>
  
  <p>I get why it evaluates to nil.name and is empty(it should be) but I don't understand why that code is even executed. </p>
  
  <p>It works by changing the test for if to.. </p>
  
  <pre><code>if file[0] != nil
  </code></pre>
  
  <p>I feel like there's an important detail I'm missing so I'd appreciate some help with understanding this.</p>
  
  <p>In my view I have:</p>
  
  <pre><code>&lt;table&gt;
    &lt;tr&gt;
      &lt;th&gt;File&lt;/th&gt;
      &lt;th&gt;Description&lt;/th&gt;
    &lt;/tr&gt;
  
    &lt;% if !@files.empty? %&gt;
      &lt;% @files.each do |file| %&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;%= file.name %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= file.description %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= link_to "Download", :controller =&gt; "files", :action =&gt; "download", :id =&gt; file.id %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= button_to "Delete", { :controller =&gt; "files", :action =&gt; "destroy", :id =&gt; file.id }, :method =&gt; "delete" %&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;% end %&gt;
  
    &lt;% else %&gt;
  
    &lt;tr&gt;
      &lt;td&gt;&lt;b&gt;No files&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;% end %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>In the controller I create an empty array called @files and then push in values later when they're created. </p>
  
  <p>Ruby 1.8.7-p72
  Rails 2.2.2</p>