title: How to find most recent post for each record in related table
body: <p>I have a one to many relationship between 'challenge' and 'entry'. I am trying to create a page that shows the most recent entry for each challenge. I don't know how to do this. So far I have something which just shows all the entries only:</p>
  
  <pre><code>discovers_controller.rb
  
   def index
      @discovers = Entry.all
    end
  end
  </code></pre>
  
  <p>discovers.html.erb</p>
  
  <pre><code>&lt;div id="grid-gallery" class="grid-gallery"&gt;
      &lt;section class="grid-wrap"&gt;
          &lt;ul class="grid"&gt;
              &lt;li class="grid-sizer"&gt;&lt;/li&gt;&lt;!-- for Masonry column width --&gt;
  
              &lt;% @discovers.each do |discover| %&gt;
              &lt;li&gt;
                  &lt;figure&gt;
                      &lt;%= image_tag discover.picture.url if discover.picture? %&gt;
                      &lt;figcaption&gt;&lt;p&gt;&lt;%= discover.blob %&gt;&lt;/p&gt;&lt;/figcaption&gt;
                  &lt;/figure&gt;
              &lt;/li&gt;
              &lt;% end %&gt;
          &lt;/ul&gt;
      &lt;/section&gt;
  </code></pre>