I am currently writing an email program in RoR 3.2 that sends mail that should be localized based on the user's language. I managed to display the correct localized views, but I'm having some difficulties with some fields that require changing the locale (for example, an object). I already read a few posts that contradict the language change before sending the email. Users have many different languages, and this will mean changing my locale every time an email is sent to the user.
I know that it will be possible to change the locale, send an email, change the locale. It doesn’t look like a rail track. Is there a proper way to do this?
Here is a snippet:
class AuthMailer < ActionMailer::Base add_template_helper(ApplicationHelper) default :from => PREDEF_MAIL_ADDRESSES::System[:general] [...] def invite(address, token, locale) @token = token @locale = locale @url = url_for(:controller => "signup_requests", :action => "new", :token => token.key, :locale => locale) mail(:subject => "Invitation", :to => address) do |format| format.html { render ("invite."+locale) } format.text { render ("invite."+locale) } end end [...] end
My views
auth_mailer invite.en.html.erb invite.en.text.erb invite.it.html.erb invite.it.text.erb ...
In short, in this case, I would like to localize the subject: subject using @locale, but without doing: I18n.locale = locale
Oktav
source share