LoginSignup
0
0

Rails7 deviseにおけるユーザ登録メールの日本語化

Posted at

はじめに

みなさん、こんにちは、 torihaziです。

今日は現在使用しているdeviseに関する記事になります。

タイトルの件について色々調べ回ったのですが、

どれもダメで今回やった方法がうまく行ったのでその方法です。

結論

app/views/devise/mailer/confirmation_instructions.html.slim を作成し、
日本語で書けばいいだけです。

どういうことか。

何もしないデフォルトの状態では、deviseは元々あるapp/views/devise/mailer/confirmation_instructions.html.slimを参照します。

app/views/devise/mailer/confirmation_instructions.html.slim
p
  | Welcome 
  = @email
  | !
p
  | You can confirm your account email through the link below:
p
  = link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token)

そしてユーザ登録したら次のメール文面が飛んできます。
スクリーンショット 2024-04-25 7.09.48.png

そのため次のファイルを新規作成し、オーバーライド?します。

# mkdir -p app/views/devise/mailer
# touch app/views/devise/mailer/confirmation_instructions.html.slim

あとはそこに対応する日本語を書くだけです。

app/views/devise/mailer/confirmation_instructions.html.slim
p
  | ようこそ 
  = @email
  | !
p
  | 下記のリンクをクリックして、本人認証をお願いします。
p
  = link_to '本人認証を行う', confirmation_url(@resource, confirmation_token: @token)

メール文面は次のようになります。
スクリーンショット 2024-04-25 7.13.10.png

終わりに

自分の調べかたが悪いのでしょうか。

devise.rbの config.mailer = Users.mailerに直せ、みたいな記事があったと思うのですが

そちらでは思っていたものと異なっていました。

とりあえず治ってよかったです。

他の方法があれば教えてください。

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