title: Rails: second-level associations/undefined method error
body: <p>I have these methods:</p>
  
  <pre><code>class Item &lt; ApplicationRecord
    has_many :fabrics
  end
  
  class Fabric &lt; ApplicationRecord
    belongs_to :item
    has_many :inventories
  end
  
  class Inventory &lt; ApplicationRecord
    belongs_to :fabric
  end
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>class InventoryController &lt; ApplicationController
  
  def index
    @inventory = Inventory.all
  end
  </code></pre>
  
  <p>And view:</p>
  
  <pre><code>&lt;% @inventory.each do |f| %&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;%= f.fabric.item %&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>ActionView::Template::Error (undefined method `item' for nil:NilClass):
  </code></pre>
  
  <p>Can someone explain why I am getting this error? Is it because of scopes? I've read Active Record Associations Guide (<a href="http://guides.rubyonrails.org/association_basics.html#belongs-to-association-reference" rel="nofollow noreferrer">http://guides.rubyonrails.org/association_basics.html#belongs-to-association-reference</a>). Under '4.1.3.2 includes' there is an example similar to my model associations which says this should be fine?</p>