Insomania Insomania - 1 month ago 5
Ruby Question

Not able to use "number_with_precision" in ApplicationHelper's method in Rails 5.0

i am using "number_with_precision" method in Rails View, it is working fine there, for example:

In Rails View: (Works Fine)

<%= number_with_precision(job.company.rating, :precision => 2) %>


But when i try to do the same in ApplicationHelper's method then it gives me the following error:
undefined method `number_with_precision' rails

here is what i have tried:

In Rails ApplicationHelper: (Gives Error)

module ApplicationHelper

def employer_overall_rating(overall_rating)
@overall_rating = number_with_precision(overall_rating, :precision => 2)
end

end


Please let me know how i can use the same in ApplicationHelper.

Thanks.

Answer

include ActionView::Helpers::NumberHelper in your application_helper.rb

Comments