在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