1

I have problem in my application with using helpers in email templates. In my application I have implemented "money-rails" to handle payment in other currencies.I have the following helper:

module CurrencyHelper

  # overriding std rails helper to use 'money' gem methods
  def number_to_currency(money, options = {})
    return '-' unless money
    currency = options.fetch(:currency, current_currency)
    date = options.fetch(:date, nil)
    should_reload = if date && !money.currency.eql?(currency)
                      ExchangeRatesManager.new(date: date).call
                    end

    money_in_currency = money.exchange_to(currency)
    ExchangeRatesManager.new.call if should_reload # should rollback to current exchange rates

    humanized_money_with_symbol(money_in_currency)
  end

end

And now I use it in my email mailers templates. When I send mail not through delayed_job everything is ok:

UserMailer.reservation_confirmation_link(@reservation).deliver

but when I send email through delayed_job: RentalOfficeMailer.delay.reservation_summary(@reservation) it not load this overwrited number_to_currency method and it not shows me proper currency. Thank's in advance for any help.

Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133
  • 1
    Does this do it? http://stackoverflow.com/questions/1416978/how-to-use-my-view-helpers-in-my-actionmailer-views – Narfanator Jul 22 '14 at 06:38
  • Seems like your helper is not getting loaded, or loaded in the wrong order. Have you tried just requiring it in the mailer? – Daiku Jul 28 '14 at 20:30

1 Answers1

2

I had the same problem where helpers are not loading in background, I solved this by calling helper method this way, in your case u can do:

Class.new.extend(CurrencyHelper).number_to_currency(money, {})
Shimaa Marzouk
  • 429
  • 4
  • 10