I have some business logic in a class
class Account < ActiveRecord::Base
…
…
def received_accounttransactions
accounttransactions.inject(0) {|total, accounttransaction| total +
accounttransaction.amount }
end
end
and a helper to display the total as in the article
http://developer.apple.com/tools/rubyonrails.html. This works but I now
want to filter the total so that an amount is only added on a condition
that the status column is ‘active’. I’ve tried to using
def accepted_accounttransactions
accounttransactions.inject(0) {|total, accounttransaction| total +
accounttransaction.amount (:condition => accounttransaction.status ==
‘accepted’) }
end
but I get an error. I tried to remove the () around the filter but get a
wrong number of arguments. What should I be doing to filter on this
business logic?
Thanks
Reg