Forum: Ruby on Rails rails3 mailer how to use a safe mailer not taking in account the I18n.locale

Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2011-05-21 12:18
(Received via mailing list)
in a multilingual site dev, I need to send localized emails...
as I need to define the @template in the mailer method, I don't want
to take in account the I18n.locale:

I wrote in my mailer method

    def welcome(user, message)
      @user = user
      language = user.language  # es_ES testing
      @template = "#{ActionMailer::Base::template_root}/user_mailer/
#{language}/welcome"
      @message = message
      mail(:to => user.email, :subject => "Welcome") do |format|
          format.html { render :layout => "/mailer/
sbga_user_mail", :template => @template }
          format.text {render :layout => false, :template =>
@template}
      end
    end

and I have the views :
views
----- user_mailer
---------- -en_GB
--------------- welcome.html.erb
--------------- welcome.text.erb
--------- -es_ES
--------------- welcome.html.erb
--------------- welcome.text.erb

but sending an email to a Spanish user,
UserMailer.welcome(current_user, "Lorem ipsum dolor").deliver , with
I18n.locale = :en_GB   raises  an error :

ActionView::MissingTemplate: Missing template /Users/yves/Sites/rails/
testsbga/app/views/user_mailer/es_ES/welcome with
{:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml],
:formats=>[:html], :locale=>[:en_GB]}
in view paths

as I18n.locale is defined to :en_GB..
it seems to be looking for  welcome.en_GB.html.erb  in /views/
user_mailer/es_ES/

how can I inform mailer that I don't want to use locale views .... ?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.