我正在尝试编写一个简单的Sinatra,但我需要动作包中的ActionView :: Helpers :: NumberHelper. http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html
问题是,我该如何安装和使用它?
irb(main):001:0> require 'action_view/helpers/number_helper'
irb(main):002:0> number_with_precision(1)
NoMethodError: undefined method `number_with_precision' for main:Object
irb(main):004:0> ActionView::Helpers::NumberHelper.number_with_precision(1)
NoMethodError: undefined method `number_with_precision' for ActionView::Helpers::NumberHelper:Module
Run Code Online (Sandbox Code Playgroud)
为什么这个简单的步骤不起作用?
而且,如果我需要所有废话:
irb(main):001:0> require 'action_pack'
irb(main):004:0> require 'action_view'
irb(main):005:0> include ActionView::Helpers::NumberHelper
irb(main):006:0> number_to_phone(12345)
NoMethodError: undefined method `starts_with?' for "12345":String
Run Code Online (Sandbox Code Playgroud)
如何理解所有这一切?为什么这个模块不起作用?为什么它不需要它需要什么?它需要什么?starts_with在哪里?
谷歌对这些问题完全保持沉默.
UPD:现在我得到以下内容
number_with_precision(1, :locale => 'fr')
TypeError: wrong argument type nil (expected Fixnum)
Run Code Online (Sandbox Code Playgroud)
在我看来,我的NumberHelper已经坏了.这不是一个好的行为.