title: Counting percentage of true elements in ruby
body: <pre><code>class Constituency &lt; ActiveRecord::Base
      has_many :votes
  end
  
  class Vote &lt;ActiveRecord::Base
      belongs_to :constituency
  end
  </code></pre>
  
  <p>I have a database with votes and each vote has boolean attribute "valid_vote".
  What I want to receive how many votes are in each constituency (in percent), but counting only valid votes. So 100% is all votes, where valid_vote == true.
  Any ideas how should I write it?</p>