title: How can I display data for the current view from a different table
body: <p>I have two tables:</p>
  
  <pre><code>Chords -     |id|chord|name|rating|artist_id|
  Artists -    |id|artist|
  </code></pre>
  
  <p>An <code>Artist</code> has many <code>Chord</code>s, and thus a <code>Chord</code> belongs to an <code>Artist</code>.</p>
  
  <p>And in the index page for "chords" I want to display chord, name, and rating from Chords table and the artist from the artists table</p>
  
  <p>This is the code for the <code>Chord</code>'s index.html.erb:</p>
  
  <pre><code>&lt;table border="1"&gt;
    &lt;% @chords.each do |chord| %&gt;
      &lt;tr&gt;
         &lt;td&gt;&lt;%= chord.artist.artist %&gt;&lt;/td&gt;
         &lt;td&gt;&lt;%= link_to chord.name, chord %&gt;&lt;/td&gt;
         &lt;td&gt;&lt;%= chord.rating %&gt;&lt;/td&gt;
         &lt;td&gt;&lt;%= chord.created_at %&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;% end %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>The error message is:</p>
  
  <blockquote>
    <p>undefined method `artist' for nil:NilClass</p>
  </blockquote>
  
  <p>Actually, at first it worked, but when I started to create the "new.html.erb" page and the create and new actions, it stopped working, that's why this is so confusing to me!</p>