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

后端 未结 11 1529
有刺的猬
有刺的猬 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:07

    Piggybacking off of @fguillen's response, I wanted to override the number_to_currency method in my ApplicationHelper module so that if the value was 0 or blank that it would output a dash instead.

    Here's my code in case you guys would find something like this useful:

    module ApplicationHelper
      def number_to_currency(value)
        if value == 0 or value.blank?
          raw "–"
        else
          ActionController::Base.helpers.number_to_currency(value)
        end
      end
    end
    

提交回复
热议问题