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

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

    You need to also include the ActionView::Helpers::NumberHelper

    class Job < ActiveRecord::Base
      include ActionView::Helpers::NumberHelper
      include JobsHelper
      def details
        return "Only " + to_dollar(part_amount_received) + 
               " out of " + to_dollar(price) + " received."
      end
    end
    

提交回复
热议问题