title: NoMethodError "undefined method `email' for nil:NilClass"
body: <p>I am having an issue with the below code in one of my views:</p>
  
  <pre><code>&lt;% @blog.comments.each do |comment| %&gt;
  &lt;h3&gt;&lt;%= comment.user.email %&gt;&lt;/h3&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Which is producing an error:</p>
  
  <pre><code>NoMethodError in Blogs#show
  ...
  undefined method `email' for nil:NilClass
  </code></pre>
  
  <p>The below code however works without error:</p>
  
  <pre><code>&lt;% @blog.comments.each do |comment| %&gt;
  &lt;%= comment.body %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Comment is declared as:</p>
  
  <pre><code>class Comment &lt; ActiveRecord::Base
    belongs_to :blog
    belongs_to :user
  end
  </code></pre>
  
  <p>And the email attribute is accessible in another view as:</p>
  
  <pre><code>&lt;% @users.each do |user| %&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;%= link_to user.username, user %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= user.email %&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>To me it looks like <strong>comment.user</strong> isn't being recognised as an instance of User model. What am I doing wrong?</p>