title: Rails 3.1 - Correct approach to remove a query from a view and process it in the controller or model
body: <p>In a view I have the following:</p>
  
  <pre><code>&lt;% @top_posts.each do |post| %&gt;
    &lt;li&gt;
      &lt;%= post.title %&gt;&lt;br /&gt; &amp;nbsp;&amp;nbsp;
      &lt;%= link_to "Most popular comment", comment_path( post.comments.order("vote_cnt DESC").first )
    &lt;/li&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I know it is considered poor form to have the <code>post.comments.order("vote_cnt DESC").first</code> query in a view.  However, since I'm combining both post and comment data to create a single list item, I'm having a hard time understanding how to get this "combo-pack" of data built in the controller.  Should I be constructing some sort of <code>@hash</code> in the controller and then iterate on <code>@hash.each</code> in the view?  Is that the right approach?  </p>
  
  <p>Or is the job for a scope on my Post model?  Is there some ActiveRecord magic that I'm missing that makes this easy?  I'm still pretty rookie at RoR, and am just beginning to see just how much I don't understand.</p>