title: Ranking in rails
body: <p>I want to create a ranking of users. It should sort users descending by count of added events.</p>
  
  <p>That's my files:</p>
  
  <p>User.rb:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :events
    #...
  end
  </code></pre>
  
  <p>ranking.html.erb:</p>
  
  <pre><code>&lt;tr&gt;
      &lt;% User.all.each  do |user| %&gt; 
      &lt;td&gt; &lt;%= user.name %&gt;&lt;/td&gt;
      &lt;td&gt; &lt;%= user.events_count %&gt;&lt;/br&gt;&lt;/td&gt; 
  &lt;% end %&gt;
   &lt;/tr&gt;
  </code></pre>
  
  <p>schema.rb:</p>
  
  <pre><code>create_table "users", force: true do |t|
    #...
    t.integer  "events_count", default: 0
  end
  </code></pre>
  
  <p>How to do it? </p>