【发布时间】:2017-05-18 21:53:51
【问题描述】:
如何让客户/指数只显示负余额的客户?
我有 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
考虑到,“余额”没有保存为数据库中表的列...
【问题讨论】:
-
当然,如果
balance保存在数据库中,它会起作用,但事实并非如此。它是一个字段,在模型中计算...
标签: ruby-on-rails activerecord