【问题标题】:In Rails 3's "rails runner", how do you use number_to_human_size() method?在 Rails 3 的“rails runner”中,如何使用 number_to_human_size() 方法?
【发布时间】:2010-09-14 00:55:58
【问题描述】:

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

【问题讨论】:

    标签: ruby-on-rails-3 actionview


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-01-20
      • 2012-04-28
      • 2016-06-18
      • 1970-01-01
      • 2013-06-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      相关资源
      最近更新 更多