How do I make the clients/index show only clients with negative balance?
I have Client.rb:
has_many :incomes
has_many :expences
def all_incomes
incomes.map(&:amount).sum
end
def all_expences
expences.map(&:amount).sum
end
def balance
all_incomes - all_expences
end
end
ClientsController.rb:
def index
@client = Client.where(:balance < 0)
end
Taking into consideration, that "balance" is not saved as a column of the table in the database...