title: Getting NoMethodError, undefined method for nil:NilClass
body: <p>I'm a beginner and am trying to show tag names associated to books (through taggings) in my book index view. The problem is that for some reason I get <code>undefined method "tags" for nil:NilClass</code> when I run:</p>
  
  <pre><code>  &lt;% for book in @books %&gt;
    &lt;div id="book"&gt;
      &lt;div class="bookHeader"&gt;
        &lt;h5 class="bookTitle"&gt;&lt;%= link_to book.title, book %&gt;&lt;/h5&gt;
      &lt;div class="bookTags"&gt;
        &lt;ul class="tags"&gt;
          &lt;li&gt;
            &lt;% for tag in @book.tags %&gt;
            &lt;%= link_to @tag.name %&gt;
            &lt;% end %&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      ...
    &lt;% end %&gt;
  </code></pre>
  
  <p>In the index file I have:</p>
  
  <pre><code>  def index
      @books = Book.all
  
      respond_to do |format|
        format.html # index.html.erb
        format.xml  { render :xml =&gt; @books }
      end
    end
  </code></pre>
  
  <p>In console, it shows that I do have associated tags:</p>
  
  <pre><code>&gt;&gt; @book = Book.find(12)
  &gt;&gt; @book.tags.count
  &gt;&gt; 3
  </code></pre>
  
  <p>Now I'm wondering if I need to construct a statement for if the books have tags or something like that. Anyone have any ideas? If I need to provide more code let me know.</p>