Rails/Devise - 使用link_to自定义flash消息(devise.en.yml)

ben*_*itr 15 ruby-on-rails devise

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

devise:
   failure:
      unconfirmed: 'You have to confirm your account before continuing.'
Run Code Online (Sandbox Code Playgroud)

使用ruby代码以获取new_user_confirmation_path的链接.

换句话说,我希望我的flash消息显示如下:

'You have to confirm your account before continuing. Didn't receive confirmation instructions?'
Run Code Online (Sandbox Code Playgroud)

哪里'没有收到确认指示?' 是new_user_confirmation_path的链接.

我想知道我是否可以在不编辑用户控制器的情况下执行此操作,因为默认情况下Devise不提供它.

感谢您的回答!

Nad*_*leh 19

new_user_confirmation_path 是一个静态网址相当于 /users/confirmation/new

所以你可以在devise.en.yml文件中执行此操作:

devise:
  failure:
    unconfirmed: "You have to confirm your account before continuing. <a href='/users/confirmation/new'>Didn't receive confirmation instructions?</a>"
Run Code Online (Sandbox Code Playgroud)

在您显示闪光灯的控制器操作中,请确保您有.html_safe例如flash[:error].html_safe