我在Rails中有这个模型:
class PaymentsDcument < ActiveRecord::Base
attr_accessible :date, :domain, :id, :total, :paid, :paid_left, :percentage
end
我希望在不在数据库中创建字段的情况下添加字段payment_total = total*percentage
。
答案 0 :(得分:1)
有些人使用Presenter来获取此类代码,但您可以使用
class PaymentsDcument < ActiveRecord::Base
attr_accessible :date, :domain, :id, :total, :paid, :paid_left, :percentage
def payment_total
total*percentage
end
end