Rails / Devise - 使用link_to自定义Flash消息(devise.en.yml) [英] Rails/Devise - Customize flash message (devise.en.yml) with a link_to

查看:75
本文介绍了Rails / Devise - 使用link_to自定义Flash消息(devise.en.yml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在devise.en.yml文件中自定义由devise
提供的以下flash msg:

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?'

哪里没有收到确认说明? to 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

new_user_confirmation_path is a static url equivalent to /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>"

在控制器的操作中,您显示闪光灯确保您有 .html_safe eg 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆