我正在完成我网站的不同本地化,我在Devise电子邮件模板中遇到了一些问题。
例如,在确认电子邮件中,我已将其全部翻译过,但使用此代码段会自动生成确认帐户的链接:
<%= link_to t('devise.mailer.confirmation_instructions.confirm_link'), confirmation_url(@resource, :confirmation_token => @token) %>
此自动生成的链接始终指向我的.com网络版,我希望它具有条件,具体取决于域(.com / .es)。当链接未自动生成时,我可以使用以下方式完成此操作:
if request.host.split('.').last == "com"
或
if request.host.split('.').last == "es"
但在这种情况下,我不知道我该怎么做。
有什么建议吗?
感谢。
答案 0 :(得分:1)
您可以将:host param添加到您的confirmation_url(@resource,:confirmation_token =&gt; @token),并在您的翻译表中查找正确的主机:
confirmation_url(@resource, :confirmation_token => @token, host: t('host'))
在您的yaml文件中,您'翻译'用户语言的正确主机,例如
en:
host: 'www.example.com'