views:

10

answers:

1

I have this code:

class Mailer < ActionMailer::Base

  def foo
    recipients "[email protected]"
    from       "[email protected]"
    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 locale to :fr, sending the email and then reverting back to :en.

Thank you!

A: 

I finally found the answer here.

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

  recipients "[email protected]"
  from       "[email protected]"
  subject    "Foo"
  body       :var => "value"
end
remi