Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined local variable or method `number_to_delimited'

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?

like image 207
Hegwin Avatar asked Sep 03 '25 01:09

Hegwin


1 Answers

Try to call ActiveSupport::NumberHelper instead.

ActiveSupport::NumberHelper.number_to_delimited(12345678)
 => "12,345,678"

Or you could do also with this:

include ActiveSupport::NumberHelper
number_to_delimited(12345678)
 => "12,345,678"

UPDATE:

I see you said in comment above that you're using haml code and you can do it like:

= ActiveSupport::NumberHelper.number_to_delimited(12345678)

Or

- include ActiveSupport::NumberHelper
= number_to_delimited(12345678)
like image 162
HashRocket Avatar answered Sep 04 '25 21:09

HashRocket