使用delayed_job设置devise mailer语言环境

时间:2015-07-02 17:12:56

标签: ruby-on-rails devise delayed-job

我通过在模型上设置以下方法异步发送我的设计电子邮件

def send_devise_notification(notification, *args) devise_mailer.send(notification, self, *args).deliver_later end

我的问题是,由于delayed_job跨越了一个新进程来发送邮件,它无法继承请求者使用的语言环境,无论用户是否使用它,都会结束回:en

我尝试用I18n.with_locale封装方法体,但它没有用:

def send_devise_notification(notification, *args) I18n.with_locale(:"pt-BR") do devise_mailer.send(notification, self, *args).deliver_later end end

考虑到区域设置是根据请求网址顶级设置的(例如.co.uk将I18n.locale设置为:en而将.com.br设置为:"pt-BR"),任何人知道如何使用正确的语言环境发送邮件?

0 个答案:

没有答案