How to change “Devise: password reset instruction email's subject”

情到浓时终转凉″ 提交于 2019-11-28 22:55:20

you can change it in devise.en.yml file in intilizer directory

And set your own subject for any mailer

                   mailer:
                     confirmation_instructions:
                       subject: 'Confirmation instructions'
                     reset_password_instructions:
                       subject: 'Reset password instructions'
                     unlock_instructions:
                       subject: 'Unlock Instructions'

I got this to work by creating my own sub-class of Devise::Mailer.

class DeviseMailer < Devise::Mailer
  def reset_password_instructions(record, token, opts={})
    mail = super
    # your custom logic
    mail.subject = "[SOME DB DATA]"
    mail
  end
end

And then modifying the devise.rb initializer to use my mailer.

# Configure the class responsible to send e-mails.
config.mailer = 'DeviseMailer'

Change option :subject:

class DeviseMailer < Devise::Mailer
  def reset_password_instructions(record, token, opts={})
    opts[:subject] = 'SOME DB DATA'
    super
  end
end

You can write your own method inside your controller and call the respective mailer template. This will help you.. Else devise views, there will be a view page to send reset instruction. Change the content there..

For default foreign language (example Japanese)

STEP 1 Create a 'ja.yml' in config/locales/ (or whatever filename)

ja:
  devise:    
    mailer:
      confirmation_instructions:
        subject: '仮会員登録完了のお知らせ'
      reset_password_instructions:
        subject: 'パスワード再設定手順のお知らせ'

STEP 2 On config/environments/development.rb

config.i18n.default_locale = :ja

STEP 3 Restart server

If you're willing to translate your Devise messages, which was my case, a better practice would be creating a new yml file in config/locale and changing your application's locale at config/application.rb

  1. To illustrate, I had to create devise.pt-BR.yml inside config/locale.

  2. Then I copied its translations from internet, on this link.

  3. Finally, I set my application's new locale at config/application.rb as follows:

    config.i18n.default_locale = :'pt-BR'
    

Hope it helps some of you guys having the same problem as mine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!