0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Rails】ActionMailerで作成したメールを簡単にプレビューで見る方法

Posted at

環境

Rails 6.0.1
Ruby 2.6.3
PostgreSQL 11.16

プレビューで見る方法

class UserRegisterMailer < ApplicationMailer
  default from: 'info@example.com'

  def registered_email(user)
    @name = user.name
    @email = user.email

    mail to: @email, subject: 'ご登録ありがとうございます'
  end
end

UserRegisterMailerならUserRegisterMailerPreviewという名前でPreviewを作成。
Previewではregistered_emailメソッドに引数を渡せないので注意。

class UserRegisterMailerPreview < ActionMailer::Preview
  def registered_email
    user = User.first
    @name = user.name
    @email = user.email

    UserRegisterMailer.registered_email(user)
  end
end

http://localhost:3000/rails/mailers/user_register_mailer/registered_email
にアクセスするとプレビューが表示される。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?