How to use the “number_to_currency” helper method in the model rather than view?

后端 未结 11 1517
有刺的猬
有刺的猬 2021-01-30 03:59

I would like to use to_dollar method in my model like this:

module JobsHelper      
  def to_dollar(amount)
    if amount < 0
      number_to_cur         


        
11条回答
  •  醉梦人生
    2021-01-30 04:10

    I know this thread is very old, but someone can look for solution for this problem in Rails 4+. Developers added ActiveSupport::NumberHelper, which can be used without accessing view related modules/classes using:

    ActiveSupport::NumberHelper.number_to_currency(amount, precision: 0)
    

提交回复
热议问题