title: Rails - Displaying Foreign Key References in a form
body: <p>I'm doing a simple exercise with two models. Sport and Teams, defined as </p>
  
  <pre>
  rails g scaffold sport name:integer
  rails g scaffold team name:integer fans:integer sport:references
  </pre>
  
  <p>(Note: The reason I'm using scaffold is rapidly prototyping so I can learn/experiment with the parts I'm not familiar with yet)</p>
  
  <p>Problem is that my "sport" (i.e. the foreign key reference) is showing like the following
  <img src="https://i.stack.imgur.com/RUhML.png" alt="enter image description here"></p>
  
  <p>So it's got that weird <code>#&lt;blahl blah&gt;</code> notation to it...</p>
  
  <pre><code>&lt;%= form_for(@team) do |f| %&gt;
    &lt;% if @team.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@team.errors.count, "error") %&gt; prohibited this team from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @team.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :name %&gt;&lt;br /&gt;
      &lt;%= f.text_field :name %&gt;
    &lt;/div&gt;
       &lt;div class="field"&gt;
      &lt;%= f.label :fans %&gt;&lt;br /&gt;
      &lt;%= f.number_field :fans %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :sport %&gt;&lt;br /&gt;
      &lt;%= f.text_field :sport %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I've tried changing the one line to <code>@team.sport.name</code> but it results in an error <code>undefined method 'Ice Hockey' for #&lt;Team:0x3e7e040&gt;</code>... Any ideas how to properly display name from here??</p>