LoginSignup
0
0

More than 1 year has passed since last update.

Deviseで、メールテンプレートの編集ができないときの対処法(template_pathではなく、headers_forを使う)

Posted at

Rails & deviseにてメールのテンプレートを変更

カスタムメーラー app/mailers/user_mailer.rbを、

class UserMailer < Devise::Mailer
  default template_path: 'users/mailer'
end

と定義したが、以下のデフォルトのメールが変更できずでした。スクリーンショット 2022-09-23 18.23.35.png

対応方法

以下のように、headers_forメソッドをオーバーライドすることで、設定したテンプレートが使用できるようです!

class UserMailer < Devise::Mailer
  # 以下の記述では動作しない
  # default template_path: 'users/mailer'

  def headers_for(action, opts)
    super.merge!(template_path: 'users/mailer')
  end
end

スクリーンショット 2022-09-23 18.27.09.png

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