Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 ActionMailer Custom Template Path? [duplicate]

Is it possible to customize the template path for Rails 3.1 ActionMailers? By default, Rails looks in:

/app/views/[mailer_class]

for the mailer view templates. However, I'd much rather organize them in:

/app/mailers/views/[mailer_class]

or at least:

/app/views/mailers/[mailer_class]

I know this was possible in 2.3 via ActionMailer's template_path config parameter, but that seems to be deprecated as of Rails 3. Is this kind of customization no longer possible?

like image 597
odonnellt Avatar asked Sep 25 '11 22:09

odonnellt


1 Answers

This sort of customization is possible still. There is a couple different ways to do this depending on how your mailers are written.

If you have the format blocks such as format.html you can pass render '/path/to/template'.

Or if you are just calling mail() there are two options for setting the path and template name, which you should just need to pass the path option:

mail(:template_path => 'mailers/[mailer_class]', :template_name => '[mailer_method]')

You should check out the Rails Guides for more detailed info.

http://guides.rubyonrails.org/action_mailer_basics.html#mailer-views

like image 189
JDutil Avatar answered Nov 15 '22 00:11

JDutil