Rails/Devise - 使用 link_to 自定义 flash 消息 (devise.en.yml) [英] Rails/Devise - Customize flash message (devise.en.yml) with a link_to
问题描述
我想自定义以下由devise提供的flash msg在 devise.en.yml 文件中:
I would like to customize the following flash msg provided by devise in the devise.en.yml file:
devise:
failure:
unconfirmed: 'You have to confirm your account before continuing.'
使用 ruby 代码以获得指向 new_user_confirmation_path 的链接.
with ruby code in order to get a link to new_user_confirmation_path.
换句话说,我希望我的 flash 消息显示如下:
in other words, I want my flash message displays something like :
'You have to confirm your account before continuing. Didn't receive confirmation instructions?'
未收到确认说明?"在哪里?是指向 new_user_confirmation_path 的链接.
where 'Didn't receive confirmation instructions?' is a link to new_user_confirmation_path.
我想知道是否可以在不编辑用户控制器的情况下执行此操作,因为 Devise 默认不提供它.
I would like to know if I can do this without editing the user controller cause Devise doesn't provide it by default.
感谢您的回答!
推荐答案
new_user_confirmation_path
是一个等效于 /users/confirmation/new
所以你可以在你的 devise.en.yml 文件中做到这一点:
So you can just do this in your devise.en.yml file:
devise:
failure:
unconfirmed: "You have to confirm your account before continuing. <a href='/users/confirmation/new'>Didn't receive confirmation instructions?</a>"
在您显示 Flash 的控制器操作中,请确保您有 .html_safe
例如flash[:error].html_safe
In the controller actions where you display your flash make sure you have .html_safe
e.g. flash[:error].html_safe
这篇关于Rails/Devise - 使用 link_to 自定义 flash 消息 (devise.en.yml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!