diff options
author | Zachary Scott <e@zzak.io> | 2015-02-17 15:04:49 -0800 |
---|---|---|
committer | Zachary Scott <e@zzak.io> | 2015-02-17 15:04:49 -0800 |
commit | af59f6d5309782e94364430bd49059b93f519381 (patch) | |
tree | 88cb86eb5e861f93945e45932b6d15debd0dd7ed | |
parent | 82d12eb9045cba57172ec7cc0786d0f72a8b711f (diff) | |
parent | 8657fb77751fd4f916c997932373aaf1966636db (diff) | |
download | rails-af59f6d5309782e94364430bd49059b93f519381.tar.gz rails-af59f6d5309782e94364430bd49059b93f519381.tar.bz2 rails-af59f6d5309782e94364430bd49059b93f519381.zip |
Merge pull request #18843 from yuki24/guides-add-guide-for-mail-preview
Add guide for Action Mailer Previews
-rw-r--r-- | guides/source/action_mailer_basics.md | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index e55ff16495..73b240ff2c 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -442,6 +442,39 @@ end Will render the HTML part using the `my_layout.html.erb` file and the text part with the usual `user_mailer.text.erb` file if it exists. +### Previewing Emails + +Action Mailer previews provide a way to see how emails look by visiting a +special URL that renders them. In the above example, the preview class for +`UserMailer` should be named `UserMailerPreview` and located in +`test/mailers/previews/user_mailer_preview.rb`. To see the preview of +`welcome_email`, implement a method that has the same name and call +`UserMailer.welcome_email`: + +```ruby +class UserMailerPreview < ActionMailer::Preview + def welcome_email + UserMailer.welcome_email(User.first) + end +end +``` + +Then the preview will be available in <http://localhost:3000/rails/mailers/user_mailer/welcome_email>. + +If you change something in `app/views/user_mailer/welcome_email.html.erb` +or the mailer itself, it'll automatically reload and render it so you can +visually see the new style instantly. A list of previews are also available +in <http://localhost:3000/rails/mailers>. + +By default, these preview classes live in `test/mailers/previews`. +This can be configured using the `preview_path` option. For example, if you +want to change it to `lib/mailer_previews`, you can configure it in +`config/application.rb`: + +```ruby +config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" +``` + ### Generating URLs in Action Mailer Views Unlike controllers, the mailer instance doesn't have any context about the |