0

在 arails 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" 

但是在 a 中rails runner呢?它作为控制器运行吗?当我打印出来时,self.class它只是说Object

4

1 回答 1

4

在您的运行脚本中,只需将其添加到顶部:

require 'rubygems'
require 'action_view'
include ActionView::Helpers::NumberHelper
于 2011-09-07T16:53:24.570 回答