1
0

More than 3 years have passed since last update.

ActionMailerの件名に自前でprefixをつける

Posted at

前提

Emailを送信するときの件名に 「[サービス名]新規登録が完了しました」 のように共通のprefixを付けていました。
そのために email_prefixer というgemを使っていたんですがメンテナンスが止まっておりgemのコードが原因のwarningに対処した話です。

DEPRECATION WARNING: `Module#parent` has 
been renamed to `module_parent`. 
`parent` is deprecated and will be removed in Rails 6.1. 

コード

app/mailers/applicatin_mailer.rb
class ApplicationMailer < ActionMailer::Base

  ..省略..

  after_action :append_prefix

  private

  def append_prefix
    mail.subject = if Rails.env.production? || Rails.env.development?
                     "[Qiita] #{mail.subject}"
                   else
                     "[Qiita(#{Rails.env.upcase})]#{mail.subject}"
                   end
  end
end

コードの中身

  • email_prefixer gemの使用はやめました。
  • ステージング環境かどうかははっきりさせたいので環境によって件名を変えています。
  • after_action内のmailでいろいろと触れるのでやりたいことは大抵できるかと思います。
1
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
1
0