我有一个网上商店。有一列价格(使用gem money)。有一列是“折扣”。如果商店经理将价格记录在“折扣”列中,商店需要显示价格(“折扣”列),我认为我需要覆盖模型中的“价格”。但是我不知道如何访问“价格”栏?
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发布于 2017-02-11 02:12:10
super可能会起作用,或者考虑使用decorators来处理这类事情。
https://stackoverflow.com/questions/42162168
复制相似问题