[英]Composite field in rails model
I have this model in Rails: 我在Rails中有这个模型:
class PaymentsDcument < ActiveRecord::Base
attr_accessible :date, :domain, :id, :total, :paid, :paid_left, :percentage
end
and I want to add the field payment_total = total*percentage
without creating the field in the database. 并且我想添加字段payment_total = total*percentage
而无需在数据库中创建该字段。
Some people use a Presenter for this kind of code, but you could go with 有些人将Presenter用于此类代码,但是您可以选择
class PaymentsDcument < ActiveRecord::Base
attr_accessible :date, :domain, :id, :total, :paid, :paid_left, :percentage
def payment_total
total*percentage
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.