Ask A Question

Notifications

You’re not receiving notifications from this thread.

Help! Sum with mysql database criterion

mbgestao asked in General

RUBY ON RAILS - Add DB column conditioned to a criterion, for example: A =1 B=1 A=1 C=4 A=2 SUMIF: A=4 B=1 C=4

Using CONTROLLER,

class PaymentsController < ApplicationController
def index
@sum_of_payments = Payment.total
end
end
MODEL

class Payment
def self.total
self.sum(:value)
end
end
VIEW

<%= @sum_of_payments %>

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.