有人知道为什么包含的方法在类方法中不起作用吗?Rails在类方法中使用包含的帮助程序
class MyClass
include ActionView::Helpers::NumberHelper
def test
puts "Uploading #{number_to_human_size 123}"
end
def self.test
puts "Uploading #{number_to_human_size 123}"
end
end
ree-1.8.7-2011.03 :004 > MyClass.new.test
Uploading 123 Bytes
=> nil
ree-1.8.7-2011.03 :005 > MyClass.test
NoMethodError: undefined method `number_to_human_size' for MyClass:Class
from /path/to/my/code.rb:9:in `test'
from (irb):5
ree-1.8.7-2011.03 :006 >
非常直接的解决方案..谢谢:) – SSR 2015-03-12 10:24:15
如果帮你请标明正确:) – 2015-03-12 17:18:33
这不是我的问题,所以我不能接受你的答案为可接受的。 :( – SSR 2015-03-13 04:30:11