Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails emails using the recipient's locale.
class NotificationMailer < ActionMailer::Base
default from: "Sender <sender@example.com>"
def mail_with_locale(headers = {}, &block)
locale = headers.delete(:locale) || I18n.default_locale
I18n.with_locale(locale) { mail_without_locale(headers, &block) }
end
alias_method_chain :mail, :locale
def notification(user)
mail to: user.email, locale: user.locale
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.