title: Rails - how do you access a foreign key object in a html.erb template? Works in console
body: <p>I am learning rails by trying to model a collectible card game.</p>
  <p>I have a champion model and a rarity model.  I have the has_many/belongs_to in the model definition and this works in the console:</p>
  <pre><code>c = Champion.find(1)
  
  c.rarity.name
  =&gt; &quot;Uncommon&quot;
  </code></pre>
  <p>When I do the same thing in a template, I get</p>
  <pre><code>&lt;%= champion.rarity.name %&gt;
  
  undefined method `name' for nil:NilClass
  </code></pre>
  <p>Any ideas on how to get this to work?</p>
  <p>This is on Rails 3.2.2.</p>
  <h3>Update: Full .erb code</h3>
  <pre><code>&lt;% @champions.each do |champion| %&gt; 
    &lt;tr&gt; 
      &lt;td&gt;&lt;%= champion.name %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= champion.rarity.name %&gt;&lt;/td&gt; 
    &lt;/tr&gt;
  &lt;% end %&gt;
  </code></pre>