在rails console
中,可以这样做:
ree-1.8.7-2010.02 > helper.number_to_human_size 1
=> "1 Byte"
ree-1.8.7-2010.02 > helper.number_to_human_size 100000
=> "97.7 KB"
ree-1.8.7-2010.02 > helper.number_to_human_size 0
=> "0 Bytes"
ree-1.8.7-2010.02 > helper.number_to_human_size 100000000
=> "95.4 MB"
但rails runner
怎么办?它是作为控制器运行的吗?当我打印self.class
时,它只是说Object
答案 0 :(得分:4)
在您的跑步者脚本中,只需将其添加到顶部:
require 'rubygems'
require 'action_view'
include ActionView::Helpers::NumberHelper