0
我有一个在线商店。有一个列价格(使用宝石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
试试'read_attribute(:price)'。 – eugen
如果'read_attribute(:price)=> nil'。如果'价格=>#<金额小数:50000货币:RUB>' –
从我所看到的情况来看,它看起来像是有一种方法价格,而不是列。你能从迁移或模式中显示表格定义吗? –