undefined local variable or method `number_to_delimited'

Viewed 1075

I'm using rails 4.2.5.

And in rails API (for v4.2.5.2) I see this helper:

number_to_delimited(number, options = {})

Formats a number with grouped thousands using delimiter (e.g., 12,324). You can customize the format in the options hash.

http://api.rubyonrails.org/classes/ActiveSupport/NumberHelper.html#method-i-number_to_delimited

But when I using this help in my views, it throws an error:

undefined methodnumber_to_delimited' for #<#:0x0000000b091b30>`

Other helpers, such like number_to_currency, all works well. What's wrong with me?

3 Answers

number_to_delimited is a method in ActiveSupport::NumberHelper which cannot be used in the view directly.

Rails provides a couple of number helpers in ActionView::Helpers::NumberHelper which are delegated the methods in ActiveSupport::NumberHelper.

  • number_to_currency
  • number_to_human
  • number_to_human_size
  • number_to_percentage
  • number_to_phone
  • number_with_delimiter
  • number_with_precision

For example, if you want to delimit the number, you should call number_with_delimiter instead, which will call number_to_delimited in the ActiveSupport::NumberHelper.

# File actionview/lib/action_view/helpers/number_helper.rb, line 244
def number_with_delimiter(number, options = {})
  delegate_number_helper_method(:number_to_delimited, number, options)
end

Hope that make sense. Cheers.

Related