【问题标题】:delayed_job and method from the helper来自助手的延迟作业和方法
【发布时间】:2014-09-12 20:08:04
【问题描述】:

我的应用程序在电子邮件模板中使用帮助程序时遇到问题。在我的应用程序中,我实现了“money-rails”来处理其他货币的付款。我有以下助手:

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

现在我在我的电子邮件邮件模板中使用它。当我不通过 delay_job 发送邮件时,一切正常:

UserMailer.reservation_confirmation_link(@reservation).deliver

但是当我通过延迟作业发送电子邮件时: RentalOfficeMailer.delay.reservation_summary(@reservation) 它没有加载这个覆盖的 number_to_currency 方法,也没有显示正确的货币。 提前感谢您的帮助。

【问题讨论】:

标签: ruby-on-rails ruby email delayed-job actionview


【解决方案1】:

我遇到了同样的问题,助手没有在后台加载,我通过这种方式调用助手方法解决了这个问题,在你的情况下你可以这样做:

Class.new.extend(CurrencyHelper).number_to_currency(money, {})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 2016-03-29
    • 1970-01-01
    相关资源
    最近更新 更多