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>' –
從我所看到的情況來看,它看起來像是有一種方法價格,而不是列。你能從遷移或模式中顯示錶格定義嗎? –