title: Rails, sum the aggregate of an attribute of all instances of a model
body: <p>I have a model Channel. The relating table has several column, for example clicks.</p>
  
  <p>So <code>Channel.all.sum(:clicks)</code> gives me the sum of clicks of all channels.</p>
  
  <p>In my model I have added a new method</p>
  
  <pre><code>def test
   123 #this is just an example
  end
  </code></pre>
  
  <p>So now, <code>Channel.first.test</code> returns 123</p>
  
  <p>What I want to do is something like <code>Channel.all.sum(:test)</code> which sums the test value of all channels.</p>
  
  <p>The error I get is that test is not a column, which of course it is not, but I hoped to till be able to build this sum.</p>
  
  <p>How could I achieve this?</p>