Set ActionMailer to use "foo.fr.erb" when 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 build the email is foo.en.erb
since I18n.locale
is set to :en
. Is there a way to bypass that and use foo.fr.erb
, other than temporarly setting the loc开发者_如何学编程ale to :fr
, sending the email and then reverting back to :en
.
Thank you!
Had trouble with this so this seems like a reasonable place to post my findings
Rails will automatically find the template based on I18n.locale
But, This is WRONG: foo.html.fr.erb
This, is the correct way to name things: foo.fr.html.erb
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
精彩评论