我試圖爲目錄中的每個單獨產品實現折扣。 我添加了新的字段到產品表 - 折扣。 如果discount.present如何重新計算product.price?如何在rails中實現產品折扣
我嘗試添加幫手product.rb:
def price
old_price = self.price
if self.discount.present?
self.price -= self.price/self.discount
else
old_price
end
但它可以讓我「堆棧級別太深」錯誤
「堆棧級別太深」幾乎總是意味着你有一個無限遞歸問題。一個函數調用自己沒有停止條件。 –