2013-04-03 65 views
0

我在我的Rails應用程序我發票模型以下現有幫手:使用助手將百分比添加到值中?

def total_price 
    line_items.to_a.sum(&:full_price) 
end 

我希望做的是有一個名爲total_vat這增加了20%到TOTAL_PRICE助手的額外幫手。這可能嗎?

我最終會添加第三個助手來計算差異,因此我只能列印應繳增值稅的金額。

回答

1

創建多個幫助程序是絕對有可能的。

def vat 
    total_price * 0.2 
end 

def total_price_including_vat 
    total_price + vat 
end 
+0

絕對完美。謝謝! – dannymcc 2013-04-03 21:29:33