title: undefined method `each' for nil:NilClass - but only when rendering on homepage
body: <p>I have a model <code>Person</code> and I want to list all 'people' on the home page of my website. </p>
  
  <p>I created a partial _index.html.erb for this, so I could use this list everywhere on my website. On index.html.erb, I render this partial.</p>
  
  <p>Now both <a href="http://localhost:3000/people/" rel="nofollow noreferrer">http://localhost:3000/people/</a> and <a href="http://localhost:3000/people/index" rel="nofollow noreferrer">http://localhost:3000/people/index</a> run fine. However, I also wanted to use the index partial on my home page. There, it gives the following error: </p>
  
  <blockquote>
    <p>undefined method `each' for nil:NilClass</p>
  </blockquote>
  
  <p>Some parts of my code:</p>
  
  <p><strong>people/_index.html.erb</strong></p>
  
  <pre><code>&lt;h2&gt;The following people exist:&lt;/h2&gt;
  &lt;table&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
    &lt;/tr&gt;
    &lt;% @people.each do |p| %&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;%= p.name %&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;% end %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>people/index.html.erb</strong></p>
  
  <pre><code>&lt;%= render 'people/index' %&gt;
  </code></pre>
  
  <p>pages/index.html.erb (This is my home page)</p>
  
  <pre><code>&lt;h1&gt;Homepage&lt;/h1&gt;
  
  &lt;%= render 'people/new' %&gt;
  &lt;%= render 'people/index' %&gt;
  </code></pre>
  
  <p><strong>routes.rb:</strong></p>
  
  <pre><code>Rails.application.routes.draw do
    root 'pages#index'
    get 'pages/index'
    get 'people/index'
    resources :people
  end
  </code></pre>
  
  <p>Part of people_controller.rb:</p>
  
  <pre><code>class PeopleController &lt; ApplicationController
  
    def index
      @people = Person.all
    end
  
    def show
      @person = Person.find(person_params)
    end
  
  ...
  </code></pre>
  
  <p>Somehow, rendering people/new (also a partial) works perfectly fine if I comment out <code>&lt;%= render 'people/index' %&gt;</code>.</p>
  
  <p>Searching for this error leads mainly to the solution "you didn't properly define @people in the controller". However, why does it then work fine on the /people/index page but not when rendering it on the homepage? Is it a routing issue? </p>
  
  <p>I hope that my question is clear and that I posted enough code snippets, thanks in advance for your help!</p>