title: Convert sql for archives to Rails ActiveRecord
body: <p>I'm having this class method inside my Post model for archives</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    def self.archives
      # fetch archives
    end
  end
  </code></pre>
  
  <p>How can I convert this sql query to ActiveRecord query in order to put it in the <code>self.archives</code> method?</p>
  
  <pre><code>SELECT YEAR(`created_at`) AS `year`, MONTHNAME(`created_at`) AS `month`, COUNT(`id`) AS `total` 
  FROM `posts` 
  GROUP BY `year`, `month` 
  ORDER BY `year` DESC, MONTH(`published_at`) DESC
  </code></pre>