インターセプター(intercept: 途中を捉える)とは、モデルのbefore_saveフックに似たフックの一種です。メールメッセージを配信前に編集したい場合にこのフックがぴったりです。staging環境で、すべてのメールをstaging@yourapp.comのメールボックスの受信箱に送りたいとしましょう。 私はインターセプターをapp/interceptorsディレクトリの下に置いて*_interceptor.rbという命名パターンを用いるのが好みです。ここでは、StagingEmailInterceptorという名前のクラスで保存します。 class StagingEmailInterceptor def self.delivering_email(message) message.to = ['staging@yourapp.com'] end end インターセプターを登録する
![Rails tips: ActionMailerのstaging向けインターセプターを作る(翻訳)|TechRacho by BPS株式会社](https://cdn-ak-scissors.b.st-hatena.com/image/square/2376df2f5d13f11255458abee4adbfe1ae5cb7f6/height=288;version=1;width=512/https%3A%2F%2Ftechracho.bpsinc.jp%2Fwp-content%2Fuploads%2F2018%2F04%2Frails_tips_actionmailer_intercepter_eyecatch.png)