我已经添加了designe\u invitable gem和一个定制邮件器。它可以正常工作,正常的设计电子邮件(如确认\u指令)可以正确读取i18n文件,但邀请\u指令不能正确读取。
这是设计图。ENyml:
en:
devise:
mailer:
confirmation_instructions:
subject: "Hi %{first_name}, please confirm your email to activate your account"
invitation_instructions:
subject: "%{first_name} has invited you to join their team!"
hello: "Oi"
someone_invited_you: "Pig"
自定义邮件程序类:
class CustomDeviseMailer < Devise::Mailer
def confirmation_instructions(record, token, opts={})
custom_options(record, opts, :confirmation_instructions)
super
end
def invitation_instructions(record, token, opts={})
custom_options(record, opts, :invitation_instructions)
super
end
private
def custom_options(record, opts, key)
opts[:subject] = I18n.t('subject', scope: [:devise, :mailer, key], first_name: record.first_name)
end
end
如果我将invitation\u instructions方法更改为:
def invitation_instructions(record, token, opts={})
custom_options(record, opts, :invitation_instructions)
opts[:subject] = "TEST"
super
end
然后邀请电子邮件主题正确更改为“测试”。
那么为什么它不读取i18n文件呢?
笔记
我还生成了默认的邀请视图,该视图也没有读取i18n文件。例如,默认视图的第一行是:
\应用程序\视图\设计\邮件\邀请\说明。html。雇员再培训局
<p>
<%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %>
</p>
它应该从i18n文件中呈现“Oi”,但它会呈现默认的“Hello”。