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

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

    I agree with all of you that this could be breaking the MVC pattern but there is always reasons to break a pattern, in my case I needed these currency formatter methods to use them in a template filter (Liquid in my case).

    At the end I found out I could access to these currency formatter methods using things like this:

    ActionController::Base.helpers.number_to_currency
    

提交回复
热议问题