gpt4 book ai didi

ruby-on-rails - rails + 设计 : Custom login failure flash messages?

转载 作者:行者123 更新时间:2023-12-02 21:58:38 32 4
gpt4 key购买 nike

我试图在用户登录失败时显示闪烁警报。但是,会有两种不同的情况:

  1. 用户输入的电子邮件存在,但密码错误。我希望显示此消息:The email address or password you entered is incorrect.

  2. 用户输入的电子邮件不存在。我希望显示此消息:The email address and password you entered do not match our records. (You provided <span class='black'>#{params[:email]}</span>)<br/><br/>
    <a href='/accounts/forgot_password' class='decorate'>Having trouble accessing your account?</a>

是否有类似于 after_sign_in_path 的钩子(Hook)我可以在哪里根据这些条件修改闪存?

更新

所以我找到了这个。但是我如何仅传递 not_found_in_database 的电子邮件变量?

en:
devise:
failure:
already_authenticated: "You are already signed in."
invalid: "The email address or password you entered is incorrect."
not_found_in_database: "The email address and password you entered do not match our records. (You provided <span class='black'>%{email}</span>)<br/><br/><a href='/accounts/forgot_password' class='decorate'>Having trouble accessing your account?</a>."

最佳答案

我最终使用了这个:http://guides.rubyonrails.org/i18n.html#passing-variables-to-translations

还有这个:

                <% if !flash[:alert].blank? %>
<% if flash[:alert][/The email address and password you entered do not match our records/] %>
<div class="flashNotice col last">
<%= t('devise.failure.not_found_in_database', resource_name: "#{params[:user][:email]}").html_safe %>
</div>
<% else %>
<!-- Style for any warning message -->
<div class="flashNotice col last"><%= flash[:alert]%></div>
<% end %>
<% end %>

关于ruby-on-rails - rails + 设计 : Custom login failure flash messages?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17327185/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com