在views/products/list.html.erb
我使用:Ruby on Rails:为什么我的类扩展无法识别?
<%= product.power.power_in_kw.to_kw if ... %>
to_kw
在lib/my_extensions.rb
定义与其它方法一起:
class Symbol
def pluralize
to_s.pluralize.to_sym
end
end
class BigDecimal
def to_kw
number_to_currency(self, :unit => "kw", :format => "%n%u", :precision => 1)
end
end
class Float
def to_dollar
number_to_currency(self)
end
end
config/environment.rb
在端部下面的行:
require 'my_extensions'
然而,我出现以下错误:
undefined method `to_kw' for #<BigDecimal:2704620,'0.555E2',8(8)>
我错过了什么?
做多元化和浮动工作? – Cory 2010-12-14 13:22:53
'pluralize'用于工作。然后我加了'to_kw'和'to_dollar',它开始失败。 – 2010-12-14 13:39:59