我添加了require 'action_view'
& include ActionView::Helpers::NumberHelper
⬇
class ApplicationController < ActionController::Base
require 'action_view'
include ActionView::Helpers::NumberHelper
而且,当我在我的=&gt;中调用它时def self.form_price formatted_price, total, total_till
puts number_with_precision(total, :precision => 2, :delimiter => ',')
收到此消息:
.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.13/lib/rails/commands/runner.rb:53:in `eval': undefined method `number_with_precision' for ApplicationController:Class (NoMethodError)
答案 0 :(得分:2)
ActionController::Base.helpers.number_with_precision(total, :precision => 2, :delimiter => ',')
答案 1 :(得分:1)
尝试使用以下内容:
view_context.number_with_precision(total, :precision => 2, :delimiter => ',')
请参阅click here