ron*_*y36 24 ruby ruby-on-rails mailer devise
我只是无法更改"密码重置说明"电子邮件的主题.我在Mailer中更改了notifer.rb以覆盖Devise默认电子邮件主题.但它不起作用.
在我的应用程序中,Devise .yml文件中有默认的电子邮件主题.但是我希望通过从数据库中提取数据来改变它.
Kas*_*ail 54
您可以在intilizer目录中的devise.en.yml文件中进行更改
并为任何邮件设置自己的主题
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions'
Run Code Online (Sandbox Code Playgroud)
小智 15
我通过创建自己的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
Run Code Online (Sandbox Code Playgroud)
然后修改devise.rb初始化程序以使用我的邮件程序.
# Configure the class responsible to send e-mails.
config.mailer = 'DeviseMailer'
Run Code Online (Sandbox Code Playgroud)
更改选项:subject:
class DeviseMailer < Devise::Mailer
def reset_password_instructions(record, token, opts={})
opts[:subject] = 'SOME DB DATA'
super
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11250 次 |
| 最近记录: |