Search code examples
ruby-on-railsrubyhelperruby-on-rails-5

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

How can I use the same in ApplicationHelper?


Solution

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