在轨道模型的综合领域

时间:2015-03-13 22:38:01

标签: ruby-on-rails ruby ruby-on-rails-3 activerecord

我在Rails中有这个模型:

class PaymentsDcument < ActiveRecord::Base
  attr_accessible :date, :domain, :id,  :total, :paid, :paid_left, :percentage
end

我希望在不在数据库中创建字段的情况下添加字段payment_total = total*percentage

1 个答案:

答案 0 :(得分:1)

有些人使用Presenter来获取此类代码,但您可以使用

class PaymentsDcument < ActiveRecord::Base
  attr_accessible :date, :domain, :id,  :total, :paid, :paid_left, :percentage

  def payment_total
    total*percentage
  end
end