Skip to content

Commit 6563a73

Browse files
committed
Merge pull request rails#33537 from ZASMan/update_action_mailer_docs_custom_view_paths
Add note for custom mailer view paths in action mailer guide. [ci skip]
2 parents 959bf6c + 16acf4f commit 6563a73

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

guides/source/action_mailer_basics.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,21 @@ use the rendered text for the text part. The render command is the same one used
422422
inside of Action Controller, so you can use all the same options, such as
423423
`:text`, `:inline` etc.
424424

425+
If you would like to render a template located outside of the default `app/views/mailer_name/` directory, you can apply the `prepend_view_path`, like so:
426+
427+
```ruby
428+
class UserMailer < ApplicationMailer
429+
prepend_view_path "custom/path/to/mailer/view"
430+
431+
# This will try to load "custom/path/to/mailer/view/welcome_email" template
432+
def welcome_email
433+
# ...
434+
end
435+
end
436+
```
437+
438+
You can also consider using the [append_view_path](https://guides.rubyonrails.org/action_view_overview.html#view-paths) method.
439+
425440
#### Caching mailer view
426441

427442
You can perform fragment caching in mailer views like in application views using the `cache` method.

0 commit comments

Comments
 (0)