title: Rails ActiveRecord sort by count of join table associations
body: <p>I have a <code>Resource</code> model that can be voted on using the "Acts As Votable" gem (<a href="https://github.com/ryanto/acts_as_votable" rel="noreferrer">Github page</a>). The voting system works perfectly but I am trying to display pages ordered by how many <code>votes</code> each <code>Resource</code> has.</p>
  
  <p>Currently my controller pulls Resources based on tags and aren't ordered:</p>
  
  <pre><code>@resources = Resource.where(language_id: "ruby")
  </code></pre>
  
  <p>If I take an individual resource and call "@resource.votes.size" it will return how many votes it has. However, votes is another table so I think some sort of join needs to be done but I have not sure how to do it. What I need is a nice ordered <code>ActiveRecord</code> collection I can display like this?</p>
  
  <blockquote>
    <p>Book name - 19 votes</p>
    
    <p>Book name - 15 votes</p>
    
    <p>Book name - 9 votes</p>
    
    <p>Book name - 8 votes</p>
  </blockquote>