title: Development log: ActionView::Template::Error (undefined method `name' for nil:NilClass):
body: <p>I'm a newbie and this is for the Rails tutorial by Richard Schneeman. This is all that is in my index.html.erb file in my view/products folder.</p>
  
  <pre><code>&lt;% first_product = Product.first %&gt;
  &lt;% lots_of_products = Product.includes(:user).all %&gt;
  &lt;ul&gt;
    &lt;% lots_of_products.each do |product| %&gt;
      &lt;li&gt;
        Product Name: "&lt;%= product.name %&gt;"" costs $&lt;%= product.price %&gt;
        Sold by &lt;%= product.user.name %&gt;
      &lt;/li&gt;
    &lt;% end %&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>The issue is with <code>&lt;%= product.user.name %&gt;</code>, which gives the error: </p>
  
  <blockquote>
    <p>NoMethodError in Products#index undefined method `name' for
    nil:NilClass.</p>
  </blockquote>
  
  <p>My controller files are vanilla and my routes.rb has:</p>
  
  <pre><code>ControllerExercise::Application.routes.draw do
    get '/products' =&gt; 'products#index'
    resources :users
  end
  </code></pre>
  
  <p>This is in the models:</p>
  
  <pre><code>class Product &lt; ActiveRecord::Base
    belongs_to :user
    attr_accessible :name, :price
  end
  
  class User &lt; ActiveRecord::Base
    has_many :products
    attr_accessible :job_title, :name
  end
  </code></pre>
  
  <p>Any and all help is greatly appreciated.</p>