Pet*_*ete 23 ruby actionviewhelper
我希望从Ruby脚本中使用ActionView :: Helpers :: NumberHelper.我还需要什么等等?
Fab*_*bio 36
~> irb
ruby-1.9.2-p180 :001 > require 'action_view'
=> true
ruby-1.9.2-p180 :002 > ActionView::Base.new.number_to_currency 43
=> "$43.00"
Run Code Online (Sandbox Code Playgroud)
mrc*_*als 22
从Rails 3.2.13开始,您可以执行以下操作:
class MyClass
include ActionView::Helpers::NumberHelper
def my_method
...
number_with_precision(number, precision: 2)
...
end
end
Run Code Online (Sandbox Code Playgroud)
你可能也需要require 'action_view'.
编辑:此答案在Rails 4.2.3中仍然有效.
| 归档时间: |
|
| 查看次数: |
8567 次 |
| 最近记录: |