title: how to show count of each category list rails
body: <p>I have the following view to show the categories with the count</p>
  
  <pre><code>&lt;% @categories.each do |category| %&gt;
  &lt;% category.sub_categories.sort.each do |sub_category| %&gt;
      &lt;li&gt;&lt;%= link_to sub_category.name, "category/#{sub_category.slug}", title: sub_category.name.capitalize %&gt; &lt;%= sub_category.posts.where(status: 1).count %&gt;&lt;/li&gt;
  &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>But I dont think using <code>where</code> in view is not good idea. Is there any other way to perform such operation.</p>
  
  <p>I am getting correct count but I need better way to do this. can anyone help</p>