Set ActionMailer to use "foo.fr.erb" if I18n.locale is set to: en

I have this code:

class Mailer < ActionMailer::Base

  def foo
    recipients "bar@example.com"
    from       "foo@example.com"
    subject    "Foo"
    body       :var => "value"
  end

end

With two views in app/views/mailer:

  • foo.en.erb
  • foo.fr.erb

When I use Mailer.deliver_foo, the view used to create the email foo.en.erb, as it is I18n.localeset to :en. Is there a way around this and use foo.fr.erb, except that temporarily set the locale to :fr, send an email, and then return to :en.

Thank!

+3
source share
2 answers

I finally found the answer here .

def foo user
  @template = "#{ActionMailer::Base::template_root}/mailer/foo.fr.erb"

  recipients "bar@example.com"
  from       "foo@example.com"
  subject    "Foo"
  body       :var => "value"
end
0
source

, .

Rails I18n.locale

, : foo.html.fr.erb

: foo.fr.html.erb

+3

Source: https://habr.com/ru/post/1770920/


All Articles