【发布时间】:2010-11-26 21:09:35
【问题描述】:
我的代码类似于:
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,那么当我将def price更改为def amount时,Rails会报告“堆栈级别太深”,然后它会抱怨number_to_currency没有定义?
【问题讨论】:
-
如果您可以将默认单位设置为 GBP 并直接使用 number_to_currency 不是更干吗?
标签: ruby-on-rails views dry