title: How can I count unique values in a table in Rails?
body: <p>I have a table "stock" which consists of many package_ids</p>
  
  <pre><code>package_id = 1  
  package_id = 3  
  package_id = 2  
  package_id = 3  
  package_id = 3  
  package_id = 4  
  package_id = 2
  </code></pre>
  
  <p>What is the most elegant way to:</p>
  
  <ul>
  <li>count each unique package_id in the db, e.g.: package_id 1 = one time
  in the db; package_id 2 = two times in the db; package_id 3 = three
  times in the DB ...</li>
  <li>echo the top 3 of package IDs afterwards</li>
  </ul>
  
  <p>I have tried this step by step:</p>
  
  <ul>
  <li>counting each single package_id (Stock.where(:package_id => 1).count)</li>
  <li>putting that all in an array</li>
  <li>and sort that array from high to low (only first 3 items)</li>
  </ul>
  
  <p>This however does not seems to be an effective path though.</p>