我有类似的代码:干燥意见
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