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

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

    Really surprised not one person has talked about using a Decorator. Their purpose is to solve the issue you are facing, and more.

    https://github.com/drapergem/draper

    EDIT: Looks like the accepted answer basically did suggest doing something like this. But yeah, you want to use decorators. Here's a great tutorial series to help you understand more:

    https://gorails.com/episodes/decorators-from-scratch?autoplay=1

    P.S. - @excid3 I accept free membership months LOL

提交回复
热议问题