开发者

Rails 3.1 ActionMailer Custom Template Path? [duplicate]

This question already has answers here: Rails mailer views in separated directory (6 answers) Closed 10 years ago.

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/ma开发者_如何学编程ilers/[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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜