覆盖方法中的值

时间:2017-02-10 14:46:50

标签: ruby-on-rails ruby-on-rails-4

我有一个在线商店。有一个列价(使用gem money)。并且有一个专栏"折扣"。如果商店经理在列"折扣"中记录价格,商店需要显示价格(列"折扣")我认为我需要覆盖"价格&# 34;在模型中。但我不知道如何访问专栏"价格"?

class Item < ActiveRecord::Base
  monetize :price_cents
  monetize :discount_cents


  def price
    if self.discount > 0
      self.discount
    else
      ?
      If I call, 
      self.price
      it turns out called once again this method.
      self[:price]
      = nil, why?
    end
  end
end

1 个答案:

答案 0 :(得分:1)

super可能有用,或者考虑使用decorators来处理此类内容。