title: Display dynamic content in footer rails
body: <p>In my footer, which is located in a partial _footer under layouts, I want to display the last 3 articles written on my app. I am getting the error <code>Undefined method each for nilClass for @articles</code> which I have sent up in the </p>
  
  <p>ArticlesController index as </p>
  
  <pre><code>    @articles=Article.order("created_at DESC").limit(3)
  </code></pre>
  
  <p>Where should I define @articles to have access to it in my whole app? I have tried to put it into application controller but was still getting an error.</p>
  
  <p>In my _footer.html.erb which in in Application layouts </p>
  
  <pre><code>       &lt;div class="col-md-3 md-margin-bottom-40"&gt;
        &lt;div class="posts"&gt;
          &lt;div class="headline"&gt;&lt;h2&gt;Latest Posts&lt;/h2&gt;&lt;/div&gt;
           &lt;% @articles.each do |article| %&gt;
          &lt;ul class="list-unstyled latest-list"&gt;
             &lt;li&gt;
              &lt;a href="#"&gt;&lt;%= article.title.titleize %&gt;&lt;/a&gt;
              &lt;small&gt;&lt;%= article.created_at.strftime("%B-%m-%Y") %&gt;&lt;/small&gt;
          &lt;/ul&gt;
        &lt;% end %&gt;
        &lt;/div&gt;
      &lt;/div&gt;&lt;!--/col-md-3--&gt;
  </code></pre>
  
  <p>_footer partial is being called here:</p>
  
  <pre><code>    &lt;body&gt;
  &lt;div class="wrapper"&gt;
   &lt;%= render "layouts/header" %&gt;
  
   &lt;%= render 'layouts/messages' %&gt;
   &lt;%= yield %&gt;
   &lt;div class="container"&gt;
   &lt;/div&gt;
   &lt;%= render "layouts/footer"%&gt;
  </code></pre>
  
  <p></p>
  
  <p></p>