Skip to content

Instantly share code, notes, and snippets.

@joergschiller
Created October 24, 2012 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joergschiller/3946788 to your computer and use it in GitHub Desktop.
Save joergschiller/3946788 to your computer and use it in GitHub Desktop.
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