I know I could define instance variables e.g:
def user_register(username, email)
@username = username
@email = email
mail(:to => email, :subject => "Welcome!", :template_name => "reg_#{I18n.locale}")
end
But, is there a way to use local variables instead, just like passing :locals to partials?
All options available in the
mailmethod can be found at http://api.rubyonrails.org/classes/ActionMailer/Base.html#method-i-mail.We know that
renderhas a:localsoption. However we can see that there is no:localsoption available formail. Therefore, no, there is no better way than to use instance variables (unless you want to use something hideous like globals or persistent database objects – don’t do this).Instance variables are what you are meant to use.