我有類似的代碼:乾燥意見
number_to_currency(line_item.price, :unit => "£")
亂扔我的意見在多種車型。由於我的申請僅以英鎊(£)進行交易,因此我不應該將其移至每個模型中,以便line_item.price
返回字符串,因爲它應該是(即number_to_currency(line_item.price, :unit => "£")
和line_item.price
是相同的。我在考慮這樣做,我應該:
def price
number_to_currency(self.price, :unit => "£")
end
但這不起作用如果price
在模型中已經定義,那麼Rails的報告「堆棧級別太深」,當我改變def price
到def amount
,然後抱怨說number_to_currency
沒有定義?
如果你可以只設置默認單位GBP並直接使用number_to_currency是不是越幹? – 2009-09-20 18:33:50