2010-09-14 54 views
1

rails console,這是可以做到這樣:在Rails 3的「rails runner」中,你如何使用number_to_human_size()方法?

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

回答

4

在你的亞軍腳本,只需將其添加到頂部:

require 'rubygems' 
require 'action_view' 
include ActionView::Helpers::NumberHelper